Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Last active September 24, 2016 12:50
Show Gist options
  • Save dengjonathan/635cb6bc0e88eef4edf8a141992cfb8e to your computer and use it in GitHub Desktop.
Save dengjonathan/635cb6bc0e88eef4edf8a141992cfb8e to your computer and use it in GitHub Desktop.
simple express node server
var express = require('express');
var app = express();
var path = require('path');
// make express look in the public directory for assets (css/js/img)
app.use(express.static(path.join(__dirname)));
app.use("/styles", express.static(__dirname + '/css'));
app.use("/scripts", express.static(__dirname + '/scripts'));
app.use("/images", express.static(__dirname + '/img'));
app.use("/components", express.static(__dirname + '/bower_components'));
// viewed at http://localhost:8080
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/views/index.html'));
});
app.listen(process.env.PORT || 8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment