Your SlideShare is downloading. ×
Node.js basics
Node.js basics
Node.js basics
Node.js basics
Node.js basics
Node.js basics
Node.js basics
Node.js basics
Node.js basics
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Node.js basics

887

Published on

Node.js basics, with a short example code

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
887
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×