java script at backend nodejs

34
JavaScript at Backend

Upload: amit-thakkar

Post on 28-Jul-2015

583 views

Category:

Technology


5 download

TRANSCRIPT

JavaScript at Backend

Agenda

Agenda1. What?

Agenda1. What?2. Installing

Agenda1. What?2. Installing3. Hello World.

Agenda1. What?2. Installing3. Hello World.4. How to run NodeJS Application.

Agenda1. What?2. Installing3. Hello World.4. How to run NodeJS Application.5. NodeJS Internal Modules

Agenda1. What?2. Installing3. Hello World.4. How to run NodeJS Application.5. NodeJS Internal Modules

○ fs(file-system) (sync vs async)

Agenda1. What?2. Installing3. Hello World.4. How to run NodeJS Application.5. NodeJS Internal Modules

○ fs(file-system) (sync vs async)○ http/https (HTTP Server with NodeJS)

Agenda1. What?2. Installing3. Hello World.4. How to run NodeJS Application.5. NodeJS Internal Modules

○ fs(file-system) (sync vs async)○ http/https (HTTP Server with NodeJS)

6. Handling HTTP Request

About Me

Amit ThakkarTech Blogger @ CodeChutney.inJavaScript LoverWorking on MEAN Stack

Twitter: @amit_thakkar01LinkedIn: linkedin.com/in/amitthakkar01Facebook: facebook.com/amit.thakkar01

What?

Installing

https://nodejs.org/download/

Hello World

You can checkout Demo form: https://github.com/AmitThakkar/JavaScript-at-Backend-NodeJS

How to run NodeJS App?

You can checkout Demo form: https://github.com/AmitThakkar/JavaScript-at-Backend-NodeJS

Node Internal Modules: fs

(function (require) { var fs = require('fs');

fs.unlinkSync('test2'); console.log('successfully deleted test2');})(require);

Node Internal Modules: fs

(function (require) { var fs = require('fs');

fs.unlinkSync('test2'); console.log('successfully deleted test2');})(require);

Node Internal Modules: fs

(function (require) { var fs = require('fs');

fs.unlinkSync('test2'); console.log('successfully deleted test2');})(require);

Node Internal Modules: fs

(function (require) { var fs = require('fs');

fs.unlink('test', function (err) { if (err) throw err; console.log('successfully deleted test'); });})(require);

Node Internal Modules: fs

(function (require) { var fs = require('fs');

fs.unlink('test', function (err) { if (err) throw err; console.log('successfully deleted test'); });})(require);

Node Internal Modules: fs

(function (require) { var fs = require('fs');

fs.unlink('test', function (err) { if (err) throw err; console.log('successfully deleted test'); });})(require);

You can checkout Demo form: https://github.com/AmitThakkar/JavaScript-at-Backend-NodeJS

Node Internal Modules: http

var http = require("http");var server = http.createServer(requestHandler);server.listen(9999, function() { console.log('Server running at http://localhost:9999/');});function requestHandler(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}

Node Internal Modules: http

var http = require("http");var server = http.createServer(requestHandler);server.listen(9999, function() { console.log('Server running at http://localhost:9999/');});function requestHandler(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}

Node Internal Modules: http

var http = require("http");var server = http.createServer(requestHandler);server.listen(9999, function() { console.log('Server running at http://localhost:9999/');});function requestHandler(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}

Node Internal Modules: http

var http = require("http");var server = http.createServer(requestHandler);server.listen(9999, function() { console.log('Server running at http://localhost:9999/');});function requestHandler(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}

Node Internal Modules: http

var http = require("http");var server = http.createServer(requestHandler);server.listen(9999, function() { console.log('Server running at http://localhost:9999/');});function requestHandler(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}

You can checkout Demo form: https://github.com/AmitThakkar/JavaScript-at-Backend-NodeJS

Handling HTTP Requestvar requestHandler = function (request, response) { var data = ""; switch (request.url) { case "/" : data = "HelloWorld"; break; case "/me" : data = "This is Me!"; break; default : data = "You lose in space"; } response.writeHead(200, {"Content-Type": "text/plain"}); response.write(data); response.end();};

Handling HTTP Requestvar requestHandler = function (request, response) { var data = ""; switch (request.url) { case "/" : data = "HelloWorld"; break; case "/me" : data = "This is Me!"; break; default : data = "You lose in space"; } response.writeHead(200, {"Content-Type": "text/plain"}); response.write(data); response.end();};

Questions??

References:Create Basic HTTP Server with Node.js