Created
May 17, 2016 00:47
-
-
Save weeksdev/ce6af22db28a82fec4e88ec66149567c to your computer and use it in GitHub Desktop.
Simple node express with static file serve
This file contains hidden or 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'), | |
| 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