[英]Node & forever wont start
ive installed node using: 我已安装的节点使用:
sudo apt-get install node
Then afterwards: 然后,然后:
sudo npm install forever --global
Now trying to run my server using 现在尝试使用运行我的服务器
forever start server.js
Nothing happens no error nothing: 什么都没有发生没有错误什么都没有:
root@socialServer:/var/www/socialAPI# forever start server.js
root@socialServer:/var/www/socialAPI# node server.js
root@socialServer:/var/www/socialAPI#
So nothing really happens :s 所以什么也没有发生:
Can anyone tell me if im missing something or have done something wrong 谁能告诉我即时消息是否遗漏或做错了什么
im using ubuntu 14.04 我正在使用Ubuntu 14.04
Server.js: Server.js:
// BASE SETUP
// =============================================================================
var express = require('express'),
bodyParser = require('body-parser');
var app = express();
var router = express.Router();
var es = require('express-sequelize');
var multer = require('multer');
var Excel = require("exceljs");
var ex = require('xlsjs');
var stream = require('stream');
var fs = require('fs');
var XLSX = require('xlsx');
var async = require('async');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
// =============================================================================
//Secure
app.all('/*', function (req, res, next) {
// CORS headers
res.header("Access-Control-Allow-Origin", "*"); // restrict it to the required domain
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
// Set custom headers for CORS
res.header('Access-Control-Allow-Headers', 'Content-type,Accept,X-Access-Token,X-Key');
if (req.method == 'OPTIONS') {
res.status(200).end();
} else {
next();
}
});
var env = app.get('local') == 'development' ? 'dev' : app.get('env');
var port = process.env.PORT || 8092;
var Sequelize = require('sequelize');
// db config
var env = "local";
var config = require('./database.json')[env];
var password = config.password ? config.password : null;
// initialize database connection
var sequelize = new Sequelize(
config.database,
config.user,
config.password,
{
port: config.port,
host: config.server,
logging: console.log,
define: {
timestamps: false
}
}
);
var user = {};
var done = {is_complete: false};
app.use(multer({
dest: './uploads/',
rename: function (fieldname, filename) {
return filename + Date.now();
},
onFileUploadStart: function (file) {
console.log(file.originalname + ' is starting ...')
},
onFileUploadComplete: function (file) {
//Redirects request to path
}
}));
var auth = require('./auth.js')(express, sequelize, router);
app.all('/api/*', [require('./middlewares/validateRequest')]);
app.use('/', router);
app.use(auth);
//Init models
var user_model = require('./social_models/user/user_model')(express, sequelize, router, user, async);
var family_model = require('./social_models/user/Family')(express, sequelize, router, user, async);
var post_model = require('./social_models/post/Post')(express, sequelize, router, user, async);
app.use(user_model);
app.use(family_model);
app.use(post_model);
// If no route is matched by now, it must be a 404
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// START THE SERVER
app.listen(port);
console.log('Magic happens on port ' + port);
As some others have said, the whole point of forever is to daemonize your node app and let it run in the background. 就像其他人所说的,永远的重点是守护节点应用程序并使其在后台运行。
If you check forever list
or top
, you will most likely see all the instances you have started. 如果您
forever list
查看forever list
或top
,则很可能会看到所有已启动的实例。 forever -h
will tell you all the different commands and options you can use to start and stop processes. forever -h
将forever -h
告诉您可用于启动和停止进程的所有不同命令和选项。
I would however suggest looking into using node's native cluster
. 但是,我建议您考虑使用节点的本机
cluster
。 I haven't use forever for a long time, but it used to be less than ideal in a production environment, and although still marked as unstable in the official docs, cluster
has proven reliable and lightweight in my experience so far. 我已经很长时间没有使用过了,但是在生产环境中使用起来并不理想,尽管在官方文档中仍然标记为不稳定,但是到目前为止,根据我的经验,
cluster
已经被证明是可靠且轻量的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.