Reputation: 20555
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
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);
Upvotes: 1
Views: 139
Reputation: 167
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 -h
will tell you all the different commands and options you can use to start and stop processes.
I would however suggest looking into using node's native 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.
Upvotes: 1