3

There are 3 file created in /config.

default.json

{
  "host": "localhost",
  "port": "PORT",
  "msg": "default"
}

local.json

{
    "host": "localhost",
    "port": 3030,
    "msg": "local"
}

dev.json

{
    "host": "localhost",
    "port": 3030,
    "msg": "dev"
}

Whenever the application runs, it should log something like info: Feathers application started on http://localhost:3030 in dev, which "dev" is the msg 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 local

but I am expecting

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

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

app.js

const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const helmet = require('helmet');
const cors = require('cors');
const logger = require('./logger');

const feathers = require('@feathersjs/feathers');
process.env['NODE_CONFIG_DIR'] = 'config/'.  // I tried to add this according to doc but still not working
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');


const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');

const authentication = require('./authentication');

const sequelize = require('./sequelize');

const app = express(feathers());

// Load app configuration
app.configure(configuration());
console.log(app.settings.msg); //<--------------------------------- show "local"
console.log(process.env.NODE_ENV); // <---------------------------- show "dev"
// Enable security, CORS, compression, favicon and body parsing
app.use(helmet({
  contentSecurityPolicy: false
}));
app.use(cors());
app.use(compress());
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ limit: '10mb', extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
// Host the public folder
app.use('/', express.static(app.get('public')));

// Set up Plugins and providers
app.configure(express.rest());
app.configure(socketio());

app.configure(sequelize);

// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(authentication);
// Set up our services (see `services/index.js`)
app.configure(services);
// Set up event channels (see channels.js)
app.configure(channels);

// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({ logger }));

app.hooks(appHooks);

module.exports = app;

Update
After I remove local.json, it works perfectly but it doesn't makes sense?

CCCC
  • 5,665
  • 4
  • 41
  • 88

0 Answers0