hellopath
hellopath

Reputation: 223

Run Node.js on a Google Compute Engine Debian server

I have a debian server running on Google Compute Engine with a host like example.com and I'm trying to run a node.js app on a directory like example.com/mynodeapp.

Node.js, NPM are installed properly on the debian server.

I'm running pm2 start main.js from the root of example.com/mynodeapp and everything running but when I go to example.com/mynodeapp, I have nothing, just the indexing of the files.

Express.js configure

main.js (entry)

var express = require('express')
var vhost = require('vhost')

express()
    .use(vhost('example.com/mynodeapp', require('./dist/index').app))
    .listen(8080)

dist/index.js

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

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

exports.app = app

Upvotes: 0

Views: 57

Answers (1)

Matthias Winkelmann
Matthias Winkelmann

Reputation: 16394

With .listen(8080) the port is set to 8080, so you'll have to change that or try example.com:8080.

Note that you will run into one of two problems, depending on your choice: Port 8080 is probably not open – you'd have to allow it in the firewall.

If you're currently getting a file listing on port 80, there's some other server running (possibly apache or nginx from the standard debian install). You will have to stop that server to free up the port.

Upvotes: 3

Related Questions