我已使用以下方式安装节点:
sudo apt-get install node
之后:
sudo npm install forever --global
现在尝试使用
运行我的服务器forever start server.js
没有任何反应没有错误:
root@socialServer:/var/www/socialAPI# forever start server.js
root@socialServer:/var/www/socialAPI# node server.js
root@socialServer:/var/www/socialAPI#
所以没有真正发生的事情:s
任何人都可以告诉我,如果我遗失了某些东西或做错了什么
即时通讯使用ubuntu 14.04
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);
答案 0 :(得分:1)
正如其他人所说,永远的重点是守护你的节点应用并让它在后台运行。
如果您选中forever list
或top
,您很可能会看到已启动的所有实例。 forever -h
将告诉您可用于启动和停止进程的所有不同命令和选项。
但我建议使用节点的原生cluster
。我已经很长时间没有使用了,但它在生产环境中曾经不太理想,虽然在官方文档中仍然标记为不稳定,cluster
在我的经验中已经证明可靠和轻量级