Last active
February 20, 2017 10:26
-
-
Save dengjonathan/722709887bce071b892476b08b425187 to your computer and use it in GitHub Desktop.
minimal express.js server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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