Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Last active February 20, 2017 10:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dengjonathan/722709887bce071b892476b08b425187 to your computer and use it in GitHub Desktop.
Save dengjonathan/722709887bce071b892476b08b425187 to your computer and use it in GitHub Desktop.
minimal express.js server
var express = require('express');
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.use("/styles", express.static(__dirname));
app.use("/images", express.static(__dirname + '/images'));
app.use("/scripts", express.static(__dirname + '/scripts'));
// viewed at based directory http://localhost:8080/
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + 'views/index.html'));
});
// add other routes below
app.get('/about', function (req, res) {
res.sendFile(path.join(__dirname + 'views/about.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