Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js feathers js-无法访问正确的配置文件_Node.js_Feathersjs - Fatal编程技术网

Node.js feathers js-无法访问正确的配置文件

Node.js feathers js-无法访问正确的配置文件,node.js,feathersjs,Node.js,Feathersjs,在/config中创建了3个文件 default.json { "host": "localhost", "port": "PORT", "msg": "default" } local.json { "host": "localhost", "port": 3030, "

在/config中创建了3个文件

default.json

{
  "host": "localhost",
  "port": "PORT",
  "msg": "default"
}
local.json

{
    "host": "localhost",
    "port": 3030,
    "msg": "local"
}
dev.json

{
    "host": "localhost",
    "port": 3030,
    "msg": "dev"
}
每当应用程序运行时,它都应该记录类似于
info:Feathers应用程序启动的日志http://localhost:3030 在dev
中,哪个“dev”是
config
文件中的
msg
变量

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)
);
我试图设置
NODE\u ENV=dev
,但每次通过
nodemon--legacy watch./src
运行应用程序时,它都会显示:

info: Feathers application started on http://localhost:3030 in local
但我期待着

info: Feathers application started on http://localhost:3030 in dev
我试图记录
process.env.NODE\u env
,但它正确地显示了
dev

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;

const path=require('path');
const-favicon=require('service-favicon');
const compress=需要(“压缩”);
常量头盔=需要(“头盔”);
const cors=需要(“cors”);
常量记录器=需要('./记录器');
const feathers=require(“@feathersjs/feathers”);
process.env['NODE\u CONFIG\u DIR']='CONFIG/'我试图根据文档添加此项,但仍然无法工作
const configuration=require('@feathersjs/configuration');
const express=require('@feathersjs/express');
const socketio=require('@feathersjs/socketio');
const middleware=require(“./middleware”);
常量服务=需要(“./服务”);
const-appHooks=require('./app.hooks');
const channels=require(“./channels”);
const authentication=require(“./authentication”);
const sequelize=require('./sequelize');
const-app=express(feathers());
//加载应用程序配置
app.configure(configuration());
console.log(app.settings.msg)//