SlideShare a Scribd company logo
Node JS
QUICK START TRAINING
Table of Content:
● About Node Js
● How to install Node JS
● About NPM
● npm init
● Node Scheduler and Http Request
● Socket.io
● Express Js Framework
● Monitor Live status of APP thorough PM2
● Deployment
About Node Js:-
● Node.js is an open source server environment
● Node.js is free
● Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
● Node.js uses JavaScript on the server
● Node.js eliminates the waiting, and simply continues with the next request.
● Node.js runs single-threaded, non-blocking, asynchronous programming, which is very memory
efficient.
● Node.js can generate dynamic page content
● Node.js can create, open, read, write, delete, and close files on the server
● Node.js can collect form data Node.js can add, delete, modify data in your database
How to install Node JS:-
1. Open the official page for Node.js downloads and download Node.js for Windows by clicking the
"Windows Installer" option
2. Run the downloaded Node.js .msi Installer - including accepting the license, selecting the
destination, and authenticating for the install (This requires Administrator privileges, and you may
need to authenticate)
3. To ensure Node.js has been installed, run node -v in your terminal - you should get something like
v6.9.5.
4. Congratulations - you've now got Node.js installed, and are ready to start building!
5. As the final step in getting Node.js installed, we'll update your version of npm - the package manager
that comes bundled with Node.js. npm install npm --global // Update the `npm` CLI client
On Ubuntu:-
sudo apt install nodejs
npm -v or npm –version
About NPM:-
What is NPM?NPM is a package manager for Node.js packages, or modules if you like. www.npmjs.com
hosts thousands of free packages to download and use. The NPM program is installed on your computer
when you install Node.js
What is a Package? A package in Node.js contains all the files you need for a module. Modules are
JavaScript libraries you can include in your project.
Download a Package
Downloading a package is very easy. Open the command line interface and tell NPM to download the
package you want. I want to download a package called "upper-case":
C:UsersYour Name>npm install upper-case
Command:npm init
package name: (mycode) testpackage-ashish
version: (1.0.0) 1.0.0
description: Project Description
entry point: (index.js) app.js
test command:
git repository: git@gitlab.com:ashishinvetech/testpackage-ashish.git
keywords: testpackage-ashish
author: Ashish Gupta
license: (ISC)
Is this OK? (yes) yes
npm login
npm publish
npm publish --access public
How to Initialize nodejs app and publish own module
● Http Request
var http = require('https');
var optionsgetmsg = {
hostname: 'portal.hpsldc.com',
port: 443,
path: '/app/api/index.php/importrtmiexftp',
method: 'GET'
};
var reqGet = http.request(optionsgetmsg, function (res) {
res.on('data', function (d) {
myData += d.toString();
});
res.on('end', function (d) {
console.log(myData);
});
});
reqGet.end();
reqGet.on('error', function (e) {
console.error(e);
});
● Node Scheduler and Http Request
Install node-cron using npm:
$ npm install --save node-cron
Import node-cron and schedule a task:
var cron = require('node-cron')
cron.schedule('* * * * *', () => {
console.log('running a task every
minute');
});
# ┌────────────── second (optional)
# │ ┌──────────── minute
# │ │ ┌────────── hour
# │ │ │ ┌──────── day of month
# │ │ │ │ ┌────── month
# │ │ │ │ │ ┌──── day of week
# │ │ │ │ │ │
# │ │ │ │ │ │
# * * * * * *
● Express JS
Fast, unopinionated, minimalist web framework for Node.js
$ npm install express --save
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
res.sendFile(__dirname + '/index.html');
})
app.post('/', function (req, res) {
res.send('Got a POST request')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Serving static files in Express
app.use('/static', express.static('public'))
http://localhost:3000/static/images/kitten.jpg
The app.locals object has properties that are local
variables within the application.
● Socket.io
npm install socket.io
var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
console.log("some one connected");
socket.on('chat message', (msg) => {
console.log(msg);
io.emit('chat message', msg);
});
});
http.listen(3000, () => {
console.log('listening on *:3000');
});
More Detail:-https://socket.io/get-started/
● PM2
1. ADVANCED, PRODUCTION PROCESS MANAGER FOR NODE.JS
2. PM2 is a daemon process manager that will help you manage and keep your application online 24/7
npm install pm2@latest -g
pm2 start app.js
pm2 monit
pm2 monit
pm2 list
pm2 stop
pm2 restart
pm2 delete
Ref:https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/
● Deployment
1. Git Clone /pull in server directory
2. npm install to install all dependency
3. pm2 start startpage.js
For multiple virtual host
https://www.digitalocean.com/community/questions/setting-up-multiple-nodejs-applications-using-
nginx-vitual-hosts
Thank You

More Related Content

What's hot

JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
Nurul Ferdous
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
Ganesh Kondal
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
Yoann Gotthilf
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
Edureka!
 
Nodejs
NodejsNodejs
Nodejs
Prem Sanil
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
ravisankar munusamy
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Arun Kumar Arjunan
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar Muthu
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
JITENDRA KUMAR PATEL
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
Arvind Devaraj
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
Edureka!
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
Brian Shannon
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Pragnesh Vaghela
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.js
Sudar Muthu
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
Jibanananda Sana
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Rob O'Doherty
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Winston Hsieh
 
Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.js
Jitendra Zaa
 

What's hot (20)

JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
Nodejs
NodejsNodejs
Nodejs
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.js
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.js
 

Similar to Node js training (1)

Node js
Node jsNode js
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
Ahmed Assaf
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
leffen
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
Bruce Li
 
Node.js
Node.jsNode.js
Node js presentation
Node js presentationNode js presentation
Node js presentation
shereefsakr
 
3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
F5 Buddy
 
Top 10 Most Important Interview Question of Node JS.
Top 10 Most Important  Interview Question of Node JS.Top 10 Most Important  Interview Question of Node JS.
Top 10 Most Important Interview Question of Node JS.
DucatNoida1
 
Nodejs
NodejsNodejs
Node js meetup
Node js meetupNode js meetup
Node js meetup
Ansuman Roy
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
TheCreativedev Blog
 
Introduction to NodeJS JSX is an extended Javascript based language used by R...
Introduction to NodeJS JSX is an extended Javascript based language used by R...Introduction to NodeJS JSX is an extended Javascript based language used by R...
Introduction to NodeJS JSX is an extended Javascript based language used by R...
JEEVANANTHAMG6
 
How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?
Inexture Solutions
 
Modern Development Tools
Modern Development ToolsModern Development Tools
Modern Development Tools
Ye Maw
 
SWT Tech Sharing: Node.js + Redis
SWT Tech Sharing: Node.js + RedisSWT Tech Sharing: Node.js + Redis
SWT Tech Sharing: Node.js + Redis
Infinity Levels Studio
 
Node in Real Time - The Beginning
Node in Real Time - The BeginningNode in Real Time - The Beginning
Node in Real Time - The Beginning
Axilis
 
Understanding of node
Understanding of nodeUnderstanding of node
Understanding of node
Mudassar Ali Sahil
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
Enoch Joshua
 
Mastering node.js, part 1 - introduction
Mastering node.js, part 1 - introductionMastering node.js, part 1 - introduction
Mastering node.js, part 1 - introduction
cNguyn826690
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Setyo Nugroho
 

Similar to Node js training (1) (20)

Node js
Node jsNode js
Node js
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
 
Node.js
Node.jsNode.js
Node.js
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
 
Top 10 Most Important Interview Question of Node JS.
Top 10 Most Important  Interview Question of Node JS.Top 10 Most Important  Interview Question of Node JS.
Top 10 Most Important Interview Question of Node JS.
 
Nodejs
NodejsNodejs
Nodejs
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Introduction to NodeJS JSX is an extended Javascript based language used by R...
Introduction to NodeJS JSX is an extended Javascript based language used by R...Introduction to NodeJS JSX is an extended Javascript based language used by R...
Introduction to NodeJS JSX is an extended Javascript based language used by R...
 
How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?
 
Modern Development Tools
Modern Development ToolsModern Development Tools
Modern Development Tools
 
SWT Tech Sharing: Node.js + Redis
SWT Tech Sharing: Node.js + RedisSWT Tech Sharing: Node.js + Redis
SWT Tech Sharing: Node.js + Redis
 
Node in Real Time - The Beginning
Node in Real Time - The BeginningNode in Real Time - The Beginning
Node in Real Time - The Beginning
 
Understanding of node
Understanding of nodeUnderstanding of node
Understanding of node
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Mastering node.js, part 1 - introduction
Mastering node.js, part 1 - introductionMastering node.js, part 1 - introduction
Mastering node.js, part 1 - introduction
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 

Recently uploaded

Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 

Recently uploaded (20)

Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 

Node js training (1)

  • 2. Table of Content: ● About Node Js ● How to install Node JS ● About NPM ● npm init ● Node Scheduler and Http Request ● Socket.io ● Express Js Framework ● Monitor Live status of APP thorough PM2 ● Deployment
  • 3. About Node Js:- ● Node.js is an open source server environment ● Node.js is free ● Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) ● Node.js uses JavaScript on the server ● Node.js eliminates the waiting, and simply continues with the next request. ● Node.js runs single-threaded, non-blocking, asynchronous programming, which is very memory efficient. ● Node.js can generate dynamic page content ● Node.js can create, open, read, write, delete, and close files on the server ● Node.js can collect form data Node.js can add, delete, modify data in your database
  • 4. How to install Node JS:- 1. Open the official page for Node.js downloads and download Node.js for Windows by clicking the "Windows Installer" option 2. Run the downloaded Node.js .msi Installer - including accepting the license, selecting the destination, and authenticating for the install (This requires Administrator privileges, and you may need to authenticate) 3. To ensure Node.js has been installed, run node -v in your terminal - you should get something like v6.9.5. 4. Congratulations - you've now got Node.js installed, and are ready to start building! 5. As the final step in getting Node.js installed, we'll update your version of npm - the package manager that comes bundled with Node.js. npm install npm --global // Update the `npm` CLI client On Ubuntu:- sudo apt install nodejs npm -v or npm –version
  • 5. About NPM:- What is NPM?NPM is a package manager for Node.js packages, or modules if you like. www.npmjs.com hosts thousands of free packages to download and use. The NPM program is installed on your computer when you install Node.js What is a Package? A package in Node.js contains all the files you need for a module. Modules are JavaScript libraries you can include in your project. Download a Package Downloading a package is very easy. Open the command line interface and tell NPM to download the package you want. I want to download a package called "upper-case": C:UsersYour Name>npm install upper-case
  • 6. Command:npm init package name: (mycode) testpackage-ashish version: (1.0.0) 1.0.0 description: Project Description entry point: (index.js) app.js test command: git repository: git@gitlab.com:ashishinvetech/testpackage-ashish.git keywords: testpackage-ashish author: Ashish Gupta license: (ISC) Is this OK? (yes) yes npm login npm publish npm publish --access public How to Initialize nodejs app and publish own module
  • 7. ● Http Request var http = require('https'); var optionsgetmsg = { hostname: 'portal.hpsldc.com', port: 443, path: '/app/api/index.php/importrtmiexftp', method: 'GET' }; var reqGet = http.request(optionsgetmsg, function (res) { res.on('data', function (d) { myData += d.toString(); }); res.on('end', function (d) { console.log(myData); }); }); reqGet.end(); reqGet.on('error', function (e) { console.error(e); });
  • 8. ● Node Scheduler and Http Request Install node-cron using npm: $ npm install --save node-cron Import node-cron and schedule a task: var cron = require('node-cron') cron.schedule('* * * * *', () => { console.log('running a task every minute'); }); # ┌────────────── second (optional) # │ ┌──────────── minute # │ │ ┌────────── hour # │ │ │ ┌──────── day of month # │ │ │ │ ┌────── month # │ │ │ │ │ ┌──── day of week # │ │ │ │ │ │ # │ │ │ │ │ │ # * * * * * *
  • 9. ● Express JS Fast, unopinionated, minimalist web framework for Node.js $ npm install express --save const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') res.sendFile(__dirname + '/index.html'); }) app.post('/', function (req, res) { res.send('Got a POST request') }) app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) }) Serving static files in Express app.use('/static', express.static('public')) http://localhost:3000/static/images/kitten.jpg The app.locals object has properties that are local variables within the application.
  • 10. ● Socket.io npm install socket.io var app = require('express')(); var http = require('http').createServer(app); var io = require('socket.io')(http); app.get('/', (req, res) => { res.sendFile(__dirname + '/index.html'); }); io.on('connection', (socket) => { console.log("some one connected"); socket.on('chat message', (msg) => { console.log(msg); io.emit('chat message', msg); }); }); http.listen(3000, () => { console.log('listening on *:3000'); }); More Detail:-https://socket.io/get-started/
  • 11. ● PM2 1. ADVANCED, PRODUCTION PROCESS MANAGER FOR NODE.JS 2. PM2 is a daemon process manager that will help you manage and keep your application online 24/7 npm install pm2@latest -g pm2 start app.js pm2 monit pm2 monit pm2 list pm2 stop pm2 restart pm2 delete Ref:https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/
  • 12. ● Deployment 1. Git Clone /pull in server directory 2. npm install to install all dependency 3. pm2 start startpage.js For multiple virtual host https://www.digitalocean.com/community/questions/setting-up-multiple-nodejs-applications-using- nginx-vitual-hosts