Skip to content

Instantly share code, notes, and snippets.

@lupomontero
Last active October 11, 2015 03:38
Show Gist options
  • Save lupomontero/3797388 to your computer and use it in GitHub Desktop.
Save lupomontero/3797388 to your computer and use it in GitHub Desktop.
Example nodejs server using express
#!/usr/bin/env node
var express = require('express');
var port = process.argv[2] || 8080;
var ip = process.argv[3] || '127.0.0.1';
var app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'hbs');
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res, next) {
res.render('index', { title: 'A test app', node_version: process.version });
});
app.listen(port, ip, function () {
console.log('nodejs ' + process.version + ' server listening on ' + ip + ':' + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment