bruh bruh - 1 year ago 69
Node.js Question

Running website on node js server

I want to access my node app from my base url path,
so I set my listening port to 80 inside my
file with express js.

Below is my
file. Credit: node static site tutorial.

var express = require('express');
var path = require('path');
var app = express();

// Define the port to run on
app.set('port', 80);

app.use(express.static(path.join(__dirname, 'public')));

// Listen for requests
var server = app.listen(app.get('port'), function() {
var port = server.address().port;
console.log('Magic happens on port ' + port);

I start my server with
node app.js
and can access my content as intended - but as soon as my connection is closed, my site is inaccessible. This is my first time experimenting with a non LAMP solution.

How can I keep my node server running on the cloud to serve my website? Is this what we call "deploying node to production?".

This is just a personal site with some static html / js files.

Answer Source

When you close the connection, you close the shell session you started node in.

Since you are running it in linux, simplest method is to run it in background node app.js &

Or you can install screen for a terminal which will stay running & can be detached from your current session.

Also, In case of unhandled errors in your code, servers programs can crash. To keep the server running & restarting when crashed use nodemon or forever.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download