Skip to content

Instantly share code, notes, and snippets.

@weeksdev
Created May 17, 2016 00:47
Show Gist options
  • Select an option

  • Save weeksdev/ce6af22db28a82fec4e88ec66149567c to your computer and use it in GitHub Desktop.

Select an option

Save weeksdev/ce6af22db28a82fec4e88ec66149567c to your computer and use it in GitHub Desktop.
Simple node express with static file serve
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
compress = require('compression');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(compress());
app.use(express.static('public'));
app.get('/api/hello', function (req, res) {
res.header('Content-Type', 'application/json');
res.send(JSON.stringify({
hello: 'world'
}));
});
var server = app.listen(process.env.PORT || 3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('nodejs app up and running, port %s', port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment