• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Node.js basics
 

Node.js basics

on

  • 1,054 views

Node.js basics, with a short example code

Node.js basics, with a short example code

Statistics

Views

Total Views
1,054
Views on SlideShare
1,054
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Node.js basics Node.js basics Presentation Transcript

    • Node.js basics “a purely evented, non-blocking infrastructure to script highly concurrent programs” Gergely Nemeth
    • Users Gergely Nemeth ● eBay ● LinkedIn ● Yahoo ● Heroku ● Medium ● Yammer ● Trello ● etc...
    • Why? Gergely Nemeth ● Uses V8 ● Non-blocking ● Event-driven ● CommonJS module format
    • When to use it? Gergely Nemeth ● Lots of non-blocking operations ● JSON APIs ● Reuse code across the client and the server ● Shelling out to unix tools ● Streaming data ● Crawling
    • When to forget it? LongDatabaseOperation.on(‘finish’, function () { //won’t be called! }); while (true) { //do some stuff } Gergely Nemeth ● Computationally heavy applications
    • When to forget it? LongDatabaseOperation.on(‘finish’, function () { //won’t be called! }); while (true) { //do some stuff } Gergely Nemeth ● Computationally heavy applications 1. All code runs in a single thread 2. Functions listen on events, act and sleep
    • How? Gergely Nemeth ● Download from: http://nodejs.org/ (or nvm on unix-based systems) ● Hello world: // Load the http module to create an http server. var http = require('http'); // Configure our HTTP server to respond with Hello World to all requests. var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello Worldn"); }); // Listen on port 8000, IP defaults to 127.0.0.1 server.listen(8000); // Put a friendly message on the terminal console.log("Server running at http://127.0.0.1:8000/"); ● Run with: node app.js
    • NPM Gergely Nemeth ● Node Packaged Modules ● package.json { "name": "MyAwesomeApplication", "version": "0.0.0", "dependencies": { "nodemailer": "~0.5.2", "express": "~3.3.4" } } ● npm install ● npm install XX --save
    • Next... Gergely Nemeth ● Node.js best practices ● Express, Passport ● Websockets with Socket.io ● MongoDB with Mongoose ● Redis ● Hogan.js (mustache)