Covering
● What is Node
● What makes Node
● What is NPM
● Why all this?
...
Hands on!
● Node.js: Hello world (cli & web)
● Express.js: Hello world
● Sails.js: Hello world
● Build a Rest API
● Test the API
● Use the API
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It's all about non-blocking,
asynchronous architecture
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It's all about non-blocking,
asynchronous architecture
This means any activity taking
a long time to finish, such as
file access, network requests,
and database operations, are
requested and put aside until the
results are ready and returned
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
Easy setup & code
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
Just 1
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
It is the server!
Just 1
But if your app crashs it
will bring down the server
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
No polling..
just callbacks
= FAST but out of order
What is Node?
Node.js® is a platform built on
Chrome's JavaScript runtime for:
● easily building fast,
● scalable network applications.
Node.js uses an:
● event-driven,
● non-blocking I/O model
that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run
across distributed devices.
No headaches with
multithreaded async I/O
Non-blocking / Asynchronous
What is
Node page manager
What is
Node page manager
NPM is a package manager for JavaScript, and is
installed by default for Node.js.
What is
Node page manager
NPM is a package manager for JavaScript, and is
installed by default for Node.js.
NPM runs through the command line and manages
dependencies for an application.
What is
Node page manager
NPM is a package manager for JavaScript, and is
installed by default for Node.js.
NPM runs through the command line and manages
dependencies for an application.
What is
Node page manager
NPM is a package manager for JavaScript, and is
installed by default for Node.js.
NPM runs through the command line and manages
dependencies for an application.
It also allows users to install Node.js applications
that are available on the npm registry.
And because of JavaScript
Mongo DB
Hand on TIME!
Installing
Mac: brew install node⎆
Linux: apt-get install nodejs⎆
Linux: apt-get install npm⎆
⎆ node -v
⎆ npm -v
Server App
⎆ Node
⎆ Console.log(“Hi”)
✎
var http = require("http");
var url = require("url");
var start = function() {
var onRequest = function(request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname);
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.write("HackerShip");
return response.end();
};
http.createServer(onRequest).listen(8888);
return console.log("Server has started.");
};
start();
⎙ balbal.js
⎆ node balbal.js
Node is the Server..
Not a framework!
✎
var http = require("http");
var url = require("url");
var start = function() {
var onRequest = function(request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname);
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.write("HackerShip");
return response.end();
};
http.createServer(onRequest).listen(8888);
return console.log("Server has started.");
};
start();
⎙ balbal.js
⎆ node balbal.js
Installing & Run
⎆ npm install -g express
⎆ express HS
⎆ cd HS
⎆ npm install
⎆ npm start
☺ http://localhost:3000/
HSroutesindex.js ✍
Installing & Run
⎆ npm install -g sails
⎆ sails new HS2
⎆ cd HS2
⎆ sails lift
☺ http://localhost:1337/
Auto-generate REST APIs
⎆ sails generate api messages
api/models/ … api/controllers/
www.getpostman.com
⎆ sails lift
Using REST APIs [HTML]
<form action="http://localhost:1337/messages" method="post">
Text: <input type="text" name="text"><br>
<input type="submit" value="Submit">
</form>
<script src="http://code.jquery.com/jquery-2.1.3.js"></script>
<script>
// ...
</script>
Using REST APIs [JS]
var myJSONData = '{"text":”some text”}';
$.ajax({type: 'POST',
url: 'http://localhost:1337/messages',
data: myJSONData,
success: function(data) {
alert("POSTED SUCCESSFULLY TO THE SERVER");
}, // Success Function
error: function(err){
alert(err.message);
}
}); // Ajax Call

Node, express & sails

  • 2.
    Covering ● What isNode ● What makes Node ● What is NPM ● Why all this? ...
  • 3.
    Hands on! ● Node.js:Hello world (cli & web) ● Express.js: Hello world ● Sails.js: Hello world ● Build a Rest API ● Test the API ● Use the API
  • 4.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
  • 5.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It's all about non-blocking, asynchronous architecture
  • 6.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It's all about non-blocking, asynchronous architecture This means any activity taking a long time to finish, such as file access, network requests, and database operations, are requested and put aside until the results are ready and returned
  • 7.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Easy setup & code
  • 8.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server!
  • 9.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server!
  • 10.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server!
  • 11.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server!
  • 12.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server!
  • 13.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server!
  • 14.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server! Just 1
  • 15.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It is the server! Just 1 But if your app crashs it will bring down the server
  • 16.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. No polling.. just callbacks = FAST but out of order
  • 17.
    What is Node? Node.js®is a platform built on Chrome's JavaScript runtime for: ● easily building fast, ● scalable network applications. Node.js uses an: ● event-driven, ● non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. No headaches with multithreaded async I/O
  • 18.
  • 19.
  • 20.
    What is Node pagemanager NPM is a package manager for JavaScript, and is installed by default for Node.js.
  • 21.
    What is Node pagemanager NPM is a package manager for JavaScript, and is installed by default for Node.js. NPM runs through the command line and manages dependencies for an application.
  • 22.
    What is Node pagemanager NPM is a package manager for JavaScript, and is installed by default for Node.js. NPM runs through the command line and manages dependencies for an application.
  • 23.
    What is Node pagemanager NPM is a package manager for JavaScript, and is installed by default for Node.js. NPM runs through the command line and manages dependencies for an application. It also allows users to install Node.js applications that are available on the npm registry.
  • 24.
    And because ofJavaScript Mongo DB
  • 25.
  • 26.
    Installing Mac: brew installnode⎆ Linux: apt-get install nodejs⎆ Linux: apt-get install npm⎆ ⎆ node -v ⎆ npm -v Server App ⎆ Node ⎆ Console.log(“Hi”)
  • 27.
    ✎ var http =require("http"); var url = require("url"); var start = function() { var onRequest = function(request, response) { var pathname = url.parse(request.url).pathname; console.log("Request for " + pathname); response.writeHead(200, { "Content-Type": "text/plain" }); response.write("HackerShip"); return response.end(); }; http.createServer(onRequest).listen(8888); return console.log("Server has started."); }; start(); ⎙ balbal.js ⎆ node balbal.js Node is the Server.. Not a framework!
  • 28.
    ✎ var http =require("http"); var url = require("url"); var start = function() { var onRequest = function(request, response) { var pathname = url.parse(request.url).pathname; console.log("Request for " + pathname); response.writeHead(200, { "Content-Type": "text/plain" }); response.write("HackerShip"); return response.end(); }; http.createServer(onRequest).listen(8888); return console.log("Server has started."); }; start(); ⎙ balbal.js ⎆ node balbal.js
  • 29.
    Installing & Run ⎆npm install -g express ⎆ express HS ⎆ cd HS ⎆ npm install ⎆ npm start ☺ http://localhost:3000/ HSroutesindex.js ✍
  • 30.
    Installing & Run ⎆npm install -g sails ⎆ sails new HS2 ⎆ cd HS2 ⎆ sails lift ☺ http://localhost:1337/
  • 31.
    Auto-generate REST APIs ⎆sails generate api messages api/models/ … api/controllers/ www.getpostman.com ⎆ sails lift
  • 32.
    Using REST APIs[HTML] <form action="http://localhost:1337/messages" method="post"> Text: <input type="text" name="text"><br> <input type="submit" value="Submit"> </form> <script src="http://code.jquery.com/jquery-2.1.3.js"></script> <script> // ... </script>
  • 33.
    Using REST APIs[JS] var myJSONData = '{"text":”some text”}'; $.ajax({type: 'POST', url: 'http://localhost:1337/messages', data: myJSONData, success: function(data) { alert("POSTED SUCCESSFULLY TO THE SERVER"); }, // Success Function error: function(err){ alert(err.message); } }); // Ajax Call