8. Agenda
1. What?
2. Installing
3. Hello World.
4. How to run NodeJS Application.
5. NodeJS Internal Modules
○ fs(file-system) (sync vs async)
9. Agenda
1. What?
2. Installing
3. Hello World.
4. How to run NodeJS Application.
5. NodeJS Internal Modules
○ fs(file-system) (sync vs async)
○ http/https (HTTP Server with NodeJS)
10. Agenda
1. What?
2. Installing
3. 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
11. About Me
Amit Thakkar
Tech Blogger @ CodeChutney.in
JavaScript Lover
Working on MEAN Stack
Twitter: @amit_thakkar01
LinkedIn: linkedin.com/in/amitthakkar01
Facebook: facebook.com/amit.thakkar01
21. 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);
22. 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);
23. 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);
24. You can checkout Demo form: https://github.com/AmitThakkar/JavaScript-at-
Backend-NodeJS
25. 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();
}
26. 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();
}
27. 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();
}
28. 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();
}
29. 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();
}
30. You can checkout Demo form: https://github.com/AmitThakkar/JavaScript-at-
Backend-NodeJS
31. Handling HTTP Request
var 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();
};
32. Handling HTTP Request
var 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();
};