Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
A NODE.JS APPLICATION
       Robbie Clutton
NOT ANOTHER NODE.JS
           HELLO WORLD
• An   application built to run on node.js

• Concepts

• Modules   used for th...
NOT ANOTHER NODE.JS
           HELLO WORLD
• An   application built to run on node.js

• Concepts

• Modules   used for th...
CONCEPTS



• CommonJS      (http://www.commonjs.org)

• Lint   (http://www.javascriptlint.com/)
NOT ANOTHER NODE.JS
           HELLO WORLD
• An   application built to run on node.js

• Concepts

• Modules   used for th...
TOOLBOX
• nodejs    - server side javascript vm (http://nodejs.org/)

• connect    - middleware (http://github.com/senchal...
CONNECT



• Middleware   framework

• Allowsfilters to be added to HTTP processing (e.g. logging,
 authentication)
CONNECT EXAMPLE
var server = Connect.createServer(
   Connect.logger(),
   function(req, res) {
       res.writeHead(200, ...
EXPRESS JS

var app = require('express').createServer();
app.get('/', function(req, res){
    res.send('hello world');
});...
EJS
res.render('show_username.ejs', {
  locals:{user:user}
});


                 <% if (user) { %>
                   <h2...
MONGOOSE
var mongoose = require('../modules/mongoose/mongoose').Mongoose;
var db = mongoose.connect('mongodb://localhost/t...
LOG4JS

var log4js = require('log4js');
log4js.addAppender(log4js.fileAppender('log/app.log'), 'controller.client');
var lo...
NOT ANOTHER NODE.JS
           HELLO WORLD
• An   application built to run on node.js

• Concepts

• Modules   used for th...
EXTRACTED MODULES
• node-daemon   - a module for start-stop functionality without
 the need for init.d scripts (http://git...
NOT ANOTHER NODE.JS
           HELLO WORLD
• An   application built to run on node.js

• Concepts

• Modules   used for th...
NDISTRO

• Bash  script that creates distributions from github for node
  binaries and modules

• Because   it’s bash, it ...
NDISTRO EXAMPLE
node 0.2.0
module senchalabs connect
module visionmedia express 1.0.0beta2
module visionmedia ejs

       ...
NOT ANOTHER NODE.JS
           HELLO WORLD
• An   application built to run on node.js

• Concepts

• Modules   used for th...
DESIGN DECISIONS


• Included   everything from:

  • directory   structure

  • bootstrap   and running the application
NOT ANOTHER NODE.JS
           HELLO WORLD
• An   application built to run on node.js

• Concepts

• Modules   used for th...
HOSTING



• Joyent   (https://no.de/)

• Heroku    (http://heroku.com/)
Upcoming SlideShare
Loading in …5
×

A nodejs application

8,358 views

Published on

A walkthrough of how I built a node.js application, showing modules, extracted code and examples.

Published in: Technology
  • Be the first to comment

A nodejs application

  1. 1. A NODE.JS APPLICATION Robbie Clutton
  2. 2. NOT ANOTHER NODE.JS HELLO WORLD • An application built to run on node.js • Concepts • Modules used for the application • Modules extracted from the application • How dependencies of modules was managed • Design decisions made during development • Hosting
  3. 3. NOT ANOTHER NODE.JS HELLO WORLD • An application built to run on node.js • Concepts • Modules used for the application • Modules extracted from the application • How dependencies of modules was managed • Design decisions made during development • Hosting
  4. 4. CONCEPTS • CommonJS (http://www.commonjs.org) • Lint (http://www.javascriptlint.com/)
  5. 5. NOT ANOTHER NODE.JS HELLO WORLD • An application built to run on node.js • Concepts • Modules used for the application • Modules extracted from the application • How dependencies of modules was managed • Design decisions made during development • Hosting
  6. 6. TOOLBOX • nodejs - server side javascript vm (http://nodejs.org/) • connect - middleware (http://github.com/senchalabs/connect) • express - sinatra like routing (http://expressjs.com/) • ndistro - dependencies (http://github.com/visionmedia/ndistro) • ejs - view templates (http://github.com/visionmedia/ejs) • mongoose- mongodb driver(http://github.com/LearnBoost/ mongoose) • log4js - logging (http://github.com/csausdev/log4js-node)
  7. 7. CONNECT • Middleware framework • Allowsfilters to be added to HTTP processing (e.g. logging, authentication)
  8. 8. CONNECT EXAMPLE var server = Connect.createServer( Connect.logger(), function(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World'); } );
  9. 9. EXPRESS JS var app = require('express').createServer(); app.get('/', function(req, res){ res.send('hello world'); }); app.listen(3000);
  10. 10. EJS res.render('show_username.ejs', { locals:{user:user} }); <% if (user) { %> <h2><%= user.name %></h2> <% } %>
  11. 11. MONGOOSE var mongoose = require('../modules/mongoose/mongoose').Mongoose; var db = mongoose.connect('mongodb://localhost/tapas'); mongoose.model('User', { 'properties': ['username', 'password', 'first', 'last', ...], 'indexes': ['first', 'last', [{'username':1},{unique: true}]], 'methods': { save: function(fn){ this.updated_at = new Date(); this.__super__(fn); } } }); module.exports = db.model('User');
  12. 12. LOG4JS var log4js = require('log4js'); log4js.addAppender(log4js.fileAppender('log/app.log'), 'controller.client'); var logger = log4js.getLogger('controller.client'); logger.setLevel('DEBUG'); logger.debug(‘hello, world’); [2010-09-28 19:50:24.816] [DEBUG] controller.user - hello, world
  13. 13. NOT ANOTHER NODE.JS HELLO WORLD • An application built to run on node.js • Concepts • Modules used for the application • Modules extracted from the application • How dependencies of modules was managed • Design decisions made during development • Hosting
  14. 14. EXTRACTED MODULES • node-daemon - a module for start-stop functionality without the need for init.d scripts (http://github.com/theteam/node- daemon) • node-properties - a module for reading JSON property files using override pattern borrowed from Ant (http://github.com/ theteam/node-properties) • tapas-models - a module for common data entities with mongodb wrappers - (http://github.com/theteam/tapas- models)
  15. 15. NOT ANOTHER NODE.JS HELLO WORLD • An application built to run on node.js • Concepts • Modules used for the application • Modules extracted from the application • How dependencies of modules was managed • Design decisions made during development • Hosting
  16. 16. NDISTRO • Bash script that creates distributions from github for node binaries and modules • Because it’s bash, it can easily be extended • Hash simple syntax • If modules are configured nicely, will symlink modules onto node execution path
  17. 17. NDISTRO EXAMPLE node 0.2.0 module senchalabs connect module visionmedia express 1.0.0beta2 module visionmedia ejs ./bin/node ./modules/senchalabs/connect ./modules/visionmedia/express ./modules/visionmedia/ejs ./lib/node/connect ./lib/node/express ./lib/node/ejs
  18. 18. NOT ANOTHER NODE.JS HELLO WORLD • An application built to run on node.js • Concepts • Modules used for the application • Modules extracted from the application • How dependencies of modules was managed • Design decisions made during development • Hosting
  19. 19. DESIGN DECISIONS • Included everything from: • directory structure • bootstrap and running the application
  20. 20. NOT ANOTHER NODE.JS HELLO WORLD • An application built to run on node.js • Concepts • Modules used for the application • Modules extracted from the application • How dependencies of modules was managed • Design decisions made during development • Hosting
  21. 21. HOSTING • Joyent (https://no.de/) • Heroku (http://heroku.com/)

×