Node JS
Node JS
Node JS
JavaScript
MEAN STACK – FULL STACK DEVELOPMENT
http Module
File System ( fs ) Module
Path Module
OS Module
Custom Module
Template String syntax
Arrow function
Following code creates an HTTP server and prints
‘Welcome to node.js Application’
About last slide block of code:
Components of a NodeJS application
1) __filename
2) __dirname
3) setTimeout( callback , milliseconds)
4) clearTimeout(timer)
5) setInterval(callback, milliseconds)
Example -1
Example -2
Example -3
Node.js - File System
How to read a text (.txt) file!!!
How to write one file content into another file
File reading
Remove file from dir
If file is not present=> error
Create dir Sync way
Remove dir Sync way
Create dir and file Async way
Use of ‘fs’ module
Event Module
Event Module : Example 1
Event Module : Example 2
Event (‘util’ module) : Example 2
Read File Stream
Read File Stream
Example - 2
Example-1 (fs module)
var fs=require('fs');
//var readStream=fs.createReadStream('hello.txt','utf8');
var readStream=fs.createReadStream('hello.txt');
readStream.setEncoding('utf8');
var data='';
readStream.on('data',function(md) {
console.log('---------------Start----------------------');
data = data + md; // data += md;
//console.log(md);
});
readStream.on('end',function(md){
console.log(data);
console.log('----------------End-----------------------');
})
Data flow control using “writeStream”
object
Data flow control using Pipes
Deals with JSON in Node.js
JSON-
Realtime example of passing JSON DATA
JSON Value
JSON- key, value pair.
Key– always string format
Passing JSON Data to the Web Browser
Output
Passing JSON Data to the Web Browser
Example - 2
Node.js – Routing Concept
Routing Concept using NodeJS app
Example-1
Routing Example - 2
Node.js - Express
Framework
NodeJS - NPM
Node Package Manager(NPM) Provides two main functionalities –
Online repositories for node.js package/modules which are searchable on
search.nodejs.org
Command line utility to install Node.js packages, do version management and
dependency management of Node.js packages.
CLI Commands are:
npm --version
Mongodb- compass
https://www.mongodb.com/download-center/compass?jmp=hero
Postman app::
https://www.getpostman.com/apps