Using Node.js Express on oLab's server


#1

Hey @bakercp, I am trying to set up a simple node server with Express on our oLab server. What ports would I have access/permissions to use? Also, where would that server live? olab.io:whateverPort?


#2

We can get it set up. Install your server to listen on the port of your choice (port > 1024). Then we’ll set up an nginx proxy to forward the port to a subdomain like http://brannonsnodejsservercoolthing.olab.io.

CB


#3

P.S. node (v0.10.22) is already installed on the server.

I set up an express test server here:

http://data.olab.io:3000/

Just followed these steps:

http://expressjs.com/3x/api.html

and used this app.js

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

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


var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

I did all of that behind a screen command to avoid setting it up as a service … which isn’t super robust, but it should work for testing.


#4

Fantastic, thanks Chris! Where does that project live in our server? Any chance I could get an “exchatter.olab.io” subdomain? No worries if not. Thank you for setting that up (so fast)!


#5

The project is just in the data user’s home directory. You should just create your own.

Have your app listen on port 6578.

I’ll forward requests on http://exchatter.olab.io:80 to port 6578 via nginx.


#6

All of the thanks! I’d love to learn a bit more about how our nginx proxy setup works. Do you have any links that you recommend?


#7

@brannondorsey https://www.digitalocean.com/community/articles/how-to-configure-the-nginx-web-server-on-a-virtual-private-server

or other Nginx articles on their community page are pretty stellar resources


#8

I’m not sure if you have access – but you can look at our configuration files here:

/etc/nginx/conf.d

I haven’t added one for your subdomain yet, but I think the DNS is working now (http://exchatter.olab.io/ brings you here I think) because it needs to be set up.

If you want to take a stab at writing a config file for your subdomain, be my guest! I’ll get you write access to the conf.d folder and sudo permission to restart nginx if you need it.