JacobHsu
10/24/2014 - 8:35 AM

#Nodejs getPost

#Nodejs getPost

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);
    });
}
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');
}