¡Esta es una revisión vieja del documento!
$ npm init$ npm install express –savevar express = require('express');
var app = express();
app.listen(3000, function() {
console.log("server started on Port 3000");
})
Take the get to de home (using request and the response):
app.get('/', fucntion(req, res) {
res.send('Hello world');
});
app.post('/users/add', function(req, res){
console.log(req.body.firstName);
});
Return a variable in its json format: res.json(person);
use is important to put it before any request.
var logger = function (req, res, next){
console.log('Logging');
next();
}
app.use(logger);
Set the view engine
app.set('view engine', 'ejs');
// with this we can render views:
res.render('index');
Set the views folder:
app.set('views', path.join(__dirname, 'views');
Add a “public” path:
var path = require('path');
app.use(express.static(path.join(__dirname, 'public'));