Created
June 9, 2015 19:19
-
-
Save lishiyo/f79d9b8971cdf4a8f9ca to your computer and use it in GitHub Desktop.
Sample Express 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
{ | |
"name": "sample-server", | |
"version": "0.0.0", | |
"description": "Code from the React tutorial.", | |
"main": "server.js", | |
"dependencies": { | |
"body-parser": "^1.4.3", | |
"express": "^4.4.5" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node server.js" | |
}, | |
"engines" : { | |
"node" : "0.12.x" | |
} | |
} |
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 fs = require('fs'); | |
var path = require('path'); | |
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
app.set('port', (process.env.PORT || 3000)); | |
app.use('/', express.static(path.join(__dirname, '/'))); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended: true})); | |
app.listen(app.get('port'), function() { | |
console.log('Server started: http://localhost:' + app.get('port') + '/'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment