Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feathers js - cannot access correct config file #620

Closed
hhchow7 opened this issue Apr 7, 2021 · 6 comments
Closed

feathers js - cannot access correct config file #620

hhchow7 opened this issue Apr 7, 2021 · 6 comments

Comments

@hhchow7
Copy link

hhchow7 commented Apr 7, 2021

2 files are created in /config.

local.json

{
    "host": "localhost",
    "port": 3030,
    "env": "local",
    "msg": "Hi I am local"
}

dev.json

{
    "host": "localhost",
    "port": 3030,
    "env": "dev",
    "msg": "Hi I am dev"
}

Whenever the application runs, it should log something like info: Feathers application started on http://localhost:3030 in Hi I am dev, which "local" is the env variable in config file.

index.js

/* eslint-disable no-console */
const logger = require('./logger');
const app = require('./app');
const port = app.get('port');
const msg = app.get('msg');
const server = app.listen(port);

process.on('unhandledRejection', (reason, p) =>
  logger.error('Unhandled Rejection at: Promise ', p, reason)
);

server.on('listening', () =>
  logger.info('Feathers application started on http://%s:%d in %s', app.get('host'), port, msg)
);

I tried to set NODE_ENV=dev, but every time I run the application by nodemon --legacy-watch ./src, it shows:

info: Feathers application started on http://localhost:3030 in Hi I am local

but I am expecting

info: Feathers application started on http://localhost:3030 in Hi I am dev

I tried to log process.env.NODE_ENV, but it shows dev correctly

@daffl
Copy link
Member

daffl commented Apr 7, 2021

app.get('env') is always set by Express to process.env.NODE_ENV. See https://stackoverflow.com/questions/34227216/process-env-vs-app-getenv-on-getting-the-express-js-environment

@hhchow7
Copy link
Author

hhchow7 commented Apr 8, 2021

app.get('env') is always set by Express to process.env.NODE_ENV. See https://stackoverflow.com/questions/34227216/process-env-vs-app-getenv-on-getting-the-express-js-environment

So what is the right way to access dev.json?

@hhchow7
Copy link
Author

hhchow7 commented Apr 8, 2021

app.get('env') is always set by Express to process.env.NODE_ENV. See https://stackoverflow.com/questions/34227216/process-env-vs-app-getenv-on-getting-the-express-js-environment

I updated the question and add field msg, would you mind taking a look?

@hhchow7
Copy link
Author

hhchow7 commented Apr 8, 2021

app.get('env') is always set by Express to process.env.NODE_ENV. See https://stackoverflow.com/questions/34227216/process-env-vs-app-getenv-on-getting-the-express-js-environment

After I remove local.json, it works perfectly but I don't think it's the correct behaviour. What is the right way to do it?

@hhchow7
Copy link
Author

hhchow7 commented Apr 8, 2021

@fratzinger
Copy link
Collaborator

Closing this issue because there's no recent activity. If the problem still exists, please use our discord server to ask questions: https://discord.com/invite/qa8kez8QBx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants