Last active
August 29, 2015 14:08
-
-
Save JacobHsu/2e7e64cc101e33185594 to your computer and use it in GitHub Desktop.
#Nodejs getPost
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 async = require('async'); | |
module.exports = function(app) { | |
app.get('/get', function (req, res){ | |
res.send('Got a GET request'); | |
console.log(req.query); | |
}); | |
app.post('/post', function (req, res) { | |
res.send('Got a POST request'); | |
console.log(req.body); | |
}); | |
app.get('*', notFound); | |
}; | |
function notFound(req, res) | |
{ | |
res.send('404', 'Page Not Found'); | |
} |
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'); | |
var bodyParser = require('body-parser'); | |
exports.start = function (config) { | |
var app = express(); | |
app.use(function(req, res, next){ | |
console.log('%s %s', req.method, req.url); | |
next(); | |
}); | |
app.use(bodyParser.json({ type: 'application/json' })); | |
app.use(bodyParser.urlencoded({type: 'application/x-www-form-urlencoded', extended:false})); | |
app.use(express.static( __dirname + '/public')); | |
var env = process.env.NODE_ENV || 'development'; | |
if ('development' == env) { | |
} | |
else { | |
} | |
require('./router')(app); | |
var server = app.listen(config.port, function() { | |
console.log('Listening on port %d', server.address().port); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment