所以我想在node.js服务器中找到一些文件,因为我觉得它们混乱了。知道我怎么能做到这一点吗?
我想要一个文件包含这样的内容 理想情况下这样的东西可以工作(文件的内容可以只是附加到文件的顶部,或者其他什么,通过某种神奇的需求声明)
settings.js文件
/* Defines a bunch of global variables and settings */
/* I understand global isa bad practice but I want this clutter out of the main server file */
express = require("express"); // Express JS
logfmt = require("logfmt"); // Heroku key-value logger
mongoose = require('mongoose'); // DB simplifier
passport = require('passport'); // Authentication
flash = require('connect-flash'); // Flash Messages
port = Number(process.env.PORT || 5000); // Locally uses port 5000, else uses port of server
configDB = require('./config/database.js');
cookieParser = require('cookie-parser');
bodyParser = require('body-parser');
session = require('express-session');
app = express(); //Express for server
主服务器文件
/ ********************************************** **** **服务器 ************************************************** /
var settings = require("./settings");
/* GLOBAL VARIABLE FOR THE SERVER. MAYBE BAD PRACTICE IDK YOLO */
server = require('http').createServer(app);
util = require("util");
io = require("socket.io").listen(server);
_settings = new settings();
//socket; // Socket controller idk tbh
/* END GLOBAL VARIABLES */
....
答案 0 :(得分:-1)
我明白了!
/ *定义一堆全局变量和设置* /
settings.js
module.exports
= {
load : function() {
express = require("express"); // Express JS
logfmt = require("logfmt"); // Heroku key-value logger
mongoose = require('mongoose'); // DB simplifier
passport = require('passport'); // Authentication
flash = require('connect-flash'); // Flash Messages
port = Number(process.env.PORT || 5000); // Locally uses port 5000, else uses port of server
configDB = require('./config/database.js');
cookieParser = require('cookie-parser');
bodyParser = require('body-parser');
session = require('express-session');
app = express(); //Express for server
}
};
server.js
var settings = require("./settings");
settings.load();
//:D