The document discusses various Node.js frameworks including Express, Socket.io, StrongLoop, SailsJS, Koa, ThinkJS, and Strapi. It provides an overview of each framework, describing what it is used for and showing basic code examples. The presentation was given by Robert Prediger on January 16, 2015 to provide an introduction to Node.js frameworks from the beginning.
5. Page 5
npm is a piece of technology, but more
importantly, it is a community.
npm makes it easy for JavaScript developers to
share and reuse code, and it makes it easy to
update the code that you're sharing.
https://www.npmjs.com/
Node.js – from the Beginning
npm
16-01-15
7. Page 7
npm
Node.js – from the Beginning16-01-15
Source: http://www.modulecounts.com/
8. Page 8
Socket.IO enables real-time bidirectional
event-based communication.
It works on every platform, browser or device,
focusing equally on reliability and speed.
USED BY EVERYONE
From Microsoft Office, Yammer, Zendesk, Trello...
to hackathon winners and little startups.
http://socket.io/
Node.js – from the Beginning
socket.io
16-01-15
9. Page 9
var express = require('express'),
app = express(),
server = require('http').createServer( app ).listen( config.port ),
io = require('socket.io').listen( server ),
numConn = 0;
...
Node.js – from the Beginning
socket.io
16-01-15
10. Page 10
...
io.on( 'connection', function(socket) {
numConn += 1;
console.log( "connected", numConn );
// event for login from socket
socket.on( "login", function ( name ) {
socket.nickname = name;
});
...
socket.on( "disconnect", function() {
numConn -= 1;
console.log( "disconnect", numConn );
});
});
Node.js – from the Beginning
socket.io
16-01-15
13. Page 13
Fast, unopinionated, minimalist
web framework for Node.js
Minimal and flexible Node.js web application framework
that provides a robust set of features for web and mobile
applications.
http://expressjs.com/
Node.js – from the Beginning
express
16-01-15
16. Page 16
var express = require('express'),
app = express() ,
router = express.Router();
// use router with prefix
app.use( "/rest", auth, router );
router.get( "/:table", function( req, res ) {
res.send( "Request: " + req.params.table );
});
router.get( "/:table/:id", function( req, res ) {
res.send( req.params );
});
app.get( "/", function( req, res ) {
console.log( "req" );
res.send( "Hello World" );
});
app.listen( 80 );
Node.js – from the Beginning
express
16-01-15
17. Page 17
var express = require('express'),
app = express();
app.use( function( req, res, next ) {
var start = new Date;
console.log( "way down", req.url );
next();
console.log( 'way back' );
console.log( 'Response-Time', new Date - start );
});
app.get( "/", function( req, res ) {
console.log( "req" );
res.send( "Hello World" );
});
app.listen( 80 );
Node.js – from the Beginning
express
16-01-15
18. Page 18
var express = require('express'),
app = express();
app.use( function( req, res, next ) {
var start = new Date;
console.log( "way down", req.url );
next();
console.log( 'way back' );
console.log( 'Response-Time', new Date - start );
});
app.get( "/", function( req, res ) {
process.nextTick( function() {
console.log( "req" );
res.send( "Hello World" );
});
});
app.listen( 80 );
Node.js – from the Beginning
express
16-01-15
19. Page 19
Enterprise Node to Power the API
Economy
No matter where you are in the lifecycle of developing
APIs with Node, StrongLoop has a complete set of
command-line and graphical tools that can work together
or independently to help you succeed.
https://strongloop.com/
Node.js – from the Beginning
StrongLoop
16-01-15
23. Page 23
The web framework of your dreams
Built for developers by a giant squid.
Sails makes it easy to build custom, enterprise-grade
Node.js apps. It is designed to emulate the familiar MVC
pattern of frameworks like Ruby on Rails, but with
support for the requirements of modern apps.
http://sailsjs.org/
Node.js – from the Beginning
SailsJS
16-01-15
24. Page 24
SailsJS
Node.js – from the Beginning16-01-15
Source: https://www.manning.com/books/sails-js-in-action
25. Page 25
SailsJS
Node.js – from the Beginning16-01-15
Source: https://www.manning.com/books/sails-js-in-action
26. Page 26
next generation web framework for
node.js
Koa is a new web framework designed by the team
behind Express, which aims to be a smaller, more
expressive, and more robust foundation for web
applications and APIs.
http://koajs.com/
Node.js – from the Beginning
Koa
16-01-15
27. Page 27
var koa = require('koa'),
app = koa();
app.use( function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
this.set('Response-Time', ms + 'ms');
});
app.use( function *(){
this.body = 'Hello World';
});
app.listen( 80 );
Node.js – from the Beginning
Koa (1.x)
16-01-15
28. Page 28
var Koa = require('koa'),
app = new Koa(),
co = require('co');
app.use( co.wrap( function *( ctx, next){
const start = new Date;
yield next();
var ms = new Date - start;
console.log( 'Response-Time', ms );
}));
app.use( ctx => {
ctx.body = 'Hello World';
});
app.listen( 80 );
Node.js – from the Beginning
Koa (2.x)
16-01-15
29. Page 29
The Web framework beyond your dreams
ThinkJS is the first Node.js MVC framework that
supporting use full ES6/7 features to develop Node.js
application.
https://thinkjs.org/
Node.js – from the Beginning
ThinkJS
16-01-15
33. Page 33
Disadvantages
Even though ThinkJS has many advantages, it has also a few
disadvantages too, for example:
• ThinkJS is a relatively new framework, the
community is not strong enough.
• ThinkJS is short of large scale applications.
Node.js – from the Beginning
ThinkJS
16-01-15
34. Page 34
Build powerful back-end with no effort.
Fast. Reusable. Easy to use.
The next generation framework for Node.js
built on top of Koa.
http://strapi.io/
Node.js – from the Beginning
strapi
16-01-15
38. Page 3816-01-15 Node.js – from the Beginning
That‘s it
Thank you very much for listening
robert.prediger@web4biz.de
Sourcecode:https://github.com/web4biz/Node.js-FromTheBeginning