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...
When to forget it?
LongDatabaseOperation.on(‘finish’, function () {
//won’t be called!
});
while (true) {
//do some stuff
...
When to forget it?
LongDatabaseOperation.on(‘finish’, function () {
//won’t be called!
});
while (true) {
//do some stuff
...
How?
Gergely Nemeth
● Download from: http://nodejs.org/ (or nvm on unix-based systems)
● Hello world:
// Load the http mod...
NPM
Gergely Nemeth
● Node Packaged Modules
● package.json
{
"name": "MyAwesomeApplication",
"version": "0.0.0",
"dependenc...
Next...
Gergely Nemeth
● Node.js best practices
● Express, Passport
● Websockets with Socket.io
● MongoDB with Mongoose
● ...
Upcoming SlideShare
Loading in...5
×

Node.js basics

905

Published on

Node.js basics, with a short example code

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
905
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Node.js basics

  1. 1. Node.js basics “a purely evented, non-blocking infrastructure to script highly concurrent programs” Gergely Nemeth
  2. 2. Users Gergely Nemeth ● eBay ● LinkedIn ● Yahoo ● Heroku ● Medium ● Yammer ● Trello ● etc...
  3. 3. Why? Gergely Nemeth ● Uses V8 ● Non-blocking ● Event-driven ● CommonJS module format
  4. 4. 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
  5. 5. When to forget it? LongDatabaseOperation.on(‘finish’, function () { //won’t be called! }); while (true) { //do some stuff } Gergely Nemeth ● Computationally heavy applications
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. Next... Gergely Nemeth ● Node.js best practices ● Express, Passport ● Websockets with Socket.io ● MongoDB with Mongoose ● Redis ● Hogan.js (mustache)

×