gpt4 book ai didi

javascript - Node & 永远不会启动

转载 作者:太空宇宙 更新时间:2023-11-04 00:55:11 24 4
gpt4 key购买 nike

我使用以下方式安装了 Node :

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

服务器.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);

最佳答案

正如其他一些人所说,永远的重点是守护您的 Node 应用程序并让它在后台运行。

如果您选中永久列表顶部,您很可能会看到您已启动的所有实例。 forever -h 将告诉您可用于启动和停止进程的所有不同命令和选项。

不过,我建议考虑使用 Node 的 native cluster 。我已经很久没有使用forever了,但它曾经在生产环境中不太理想,尽管在官方文档中仍然标记为不稳定,但到目前为止,cluster在我的经验中已经被证明是可靠且轻量级的。

关于javascript - Node & 永远不会启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30174488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com