0

The project runs without any errors when run from Visual Studio Code by runung the cmd : npm start. But when runing the project as a windows service I´m getting an error about the PORT. The PORT=8080 is initialized in the (Environment file) env. file.

Bellow is the env. file:

NODE_ENV=production

# hapi server config
PORT=8080
HOST=localhost
HOST_URL=http://localhost:8080
COOKIE_ENCRYPT_PWD=xxxxxxxxxx...

#sql server config
SQL_USER=xxxxx
SQL_PASSWORD=xxxxxxxx
SQL_DATABASE=xxxxxxxx
SQL_SERVER=computer\SQLEXPRESS
SQL_ENCRYPT=false

#okta config
OKTA_ORG_URL=https://dev-000000.okta.com
OKTA_CLIENT_ID=xxxxxxxx
OKTA_CLIENT_SECRET=xxxxxxxxxxx

Bellow is the config file:

"use strict";

const dotenv = require( "dotenv" );
const assert = require( "assert" );

dotenv.config();

const {
    PORT,
    HOST,
    HOST_URL,
    COOKIE_ENCRYPT_PWD,
    SQL_SERVER,
    SQL_PORT,
    SQL_DATABASE,
    SQL_USER,
    SQL_PASSWORD,
    OKTA_ORG_URL,
    OKTA_CLIENT_ID,
    OKTA_CLIENT_SECRET
} = process.env;

const sqlEncrypt = process.env.SQL_ENCRYPT === "false";

assert( PORT, "PORT is required" );
assert( HOST, "HOST is required" );

module.exports = {
    port: PORT,
    host: HOST,
    url: HOST_URL,
    cookiePwd: COOKIE_ENCRYPT_PWD,
    sql: {
        server: SQL_SERVER,
        port: SQL_PORT,
        database: SQL_DATABASE,
        user: SQL_USER,
        password: SQL_PASSWORD,
        options: {
            encrypt: sqlEncrypt,
            enableArithAbort: true
        }
    },
    okta: {
        url: OKTA_ORG_URL,
        clientId: OKTA_CLIENT_ID,
        clientSecret: OKTA_CLIENT_SECRET
    }
};

the error is as follows:

assert.js:386
    throw err;
    ^
AssertionError [ERR_ASSERTION]: PORT is required
    at Object.<anonymous> (C:\inetpub\apis\routis\src\config.js:25:1)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (C:\inetpub\apis\routis\src\index.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}

1 Answers1

0

extension of dotenv file is .env, Check once for that.

Vijay
  • 228
  • 3
  • 8