Express by Examples

How express works

Bootstrap file is /bin/www

That file is including /app.js  with  var app = require('../app');

Inside app.js application starts with var app = express();

 

Routing

app.js

var routes = require('./routes/index');       //module export from /routes/index.js

app.use('/', routes);     //define root directory for all routes in index.js

 

Two basic methods used in routes are:

res.send('some string');

res.render('index', { title: 'Express' });    //calls /views/index.hjs  -hogan template

 

res.send(404);   // Status 404 Not Found will be sent (see in Firebug-Net)

res.send(200);    // Status 200 OK will be sent