A
A
Alexander2017-11-15 22:01:02
MongoDB
Alexander, 2017-11-15 22:01:02

Why node.js application does not work on hosting?

I’m just starting to understand the node, I made a simple server, locally everything works as it should on the computer, but for some reason it doesn’t work on the hosting, the server starts, but if you open it in the browser, then “Can’t connect”. Here is the minified code:
var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var MongoClient = require('mongodb').MongoClient;
vardb;
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.get('/, function(req, res, next) {
res.send('Hello user');
});
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
MongoClient.connect('connect to database here', function (err, database) {
if(err){
return console.log(err);
}
db = database;
app.listen(3012, function () {
console.log( 'Server started');
})
});
module.exports = app;
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2017-11-15
@VELIK505

You need to look at the logs. Run the node through forever with logging.

forever --minUptime 1000 --spinSleepTime 1000 --pidFile=/var/run/forever.pid -l /..../forever.log -a -e /..../err.log start -c "node --expose-gc --nouse-idle-notification --max-old-space-size=8192" /..../index.js -p 3000 -h mysite.com

M
mrxakerrus, 2017-11-15
@mrxakerrus

Perhaps you need to allow access to the port through iptables. And the first thing you had to do was show us the server startup logs on the server, maybe you didn’t install npm packages, in 80% of cases the logs have all the necessary information

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question