phantom phantom - 1 year ago 138
Node.js Question

deploying node add on server without using localhost

I have a node app that I am trying to deploy on my server. I have an

file in a public folder and an
file. If I navigate to the project in the command line and run
node app.js
it runs the app on
and shows the

Now that I have uploaded this to my server I am wondering what I need to do, and change (if anything) in my
file so that i can visit the site without visiting
, but instead the actual url.

I have tried
, but this doesn't work.

var express = require('express')
var app = express();
app.use(express.static(__dirname + '/public'))

app.get('/', function (req, res) {
res.send('Hello World!')

app.listen(8888, function () {
console.log('Example app listening on port 8888!')

Answer Source

"Server" is a word with two primary meanings in software development.

It can mean either "A piece of software that listens on a network" or "A computer running that kind of software".

So having uploaded the JavaScript program to the remote computer that is your server you need to do exactly the same as you did on your own computer.

i.e. you need to get a terminal on the server and run node app.js

It will then be available at

(More advanced uses would involve using software like forever or system.d to run it automatically as a background process).

If you were using the term server with the other meaning (i.e. you mean "Apache HTTP" or "IIS" or similar), then you are out of luck.

Using Node for server side code means running a server written in JavaScript.

To use this in combination with something like Apache, you would either:

  1. Run the Node server instead of Apache
  2. Run the Node server on a different port and point some services at that port explicitly
  3. Run the Node server on a different port and use something like ProxyPass to have Apache relay requests to it
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download