13. USING A PROCESS MANAGER
Easy clustering and scaling without altering application
code
StrongLoop Process Manager (strong-pm)
PM2
Comparison Chart
Forever
22. STRONGLOOP AND NGINX
If you're using strong-pm you can use the
!
StrongLoop nginx
controller
~$ npm install g strongnginxcontroller
~$ slnginxctlinstall
Install the Controller on the load balancing host...
45. ORDER MATTERS!
Middleware are executed in the order specified
app.use( express.logger('dev') );
app.use( myAuthModule() );
app.use( bodyParser.json() );
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
// Routing middleware...
46. MIDDLEWARE - WHEN DOES IT END?
Middleware processing ends when next() is not called
(or an error is generated)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/about', function aboutUs(req, res, next) {
res.send('We are StrongLoop!');
// no call to next()
});
app.get('/user', ...);
53. TEMPLATES
Small blocks that we can plug data into at run-time
// /views/index.jade
doctype html
html
head
title #{title}
body
section.mainbody.clear
#{homepageText}
58. THE 4.0 ROUTER INTERFACE
// in routes/users.js
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
// Get a list of users...
res.render('user/list', { results: users });
});
router.get('/:id', function(req, res, next) {
// Get a single user...
res.render('user/myaccount', { user: user });
});
router.post('/', function(req, res, next) {
// Create a user...
res.redirect('user/myaccount', { user: user });
});
module.exports = router;
59. THE 4.0 ROUTER INTERFACE
// in app.js
var express = require('express'),
...;
var app = express();
// app config and middleware...
app.use('/users', require('./routes/users'));
66. HTTP STATUS CODES
2XX: for successfully processed requests
3XX: for redirections or cache information
4XX: for client-side errors
5XX: for server-side errors