Introduction to Node JS
Course Content
• Node.js Introduction
• Node.js Environment Setup
• Node.js First Application
• Node.js REPL Terminal
• Node.js Command Line Options
• Node.js Package Manager (NPM)
• Node.js Callbacks Concept
• Node.js Upload Files
• Node.js Send an Email
• Node.js Events
• Node.js Event Loop
• Node.js Event Emitter
• Node.js Debugger
• Node.js Global Objects
• Node.js Console
• Node.js Process
• Node.js File System
• Node.js Streams
• Node.js Scaling Application
• Node.js Packaging
Grad system
Mid Term Exam 20 degree
Project 10 degree
Practical exam 10 degree
Final exam 60 degree
Reference Books
- Learning Node by Shelley Powers
- The Node.js Handbook by Flavio copes
• What is Node.js?
Node.js is not a programming language like Python, Java or C/C++.
Node.js is a runtime, similar to Java virtual machine, that converts
JavaScript code into machine code. It is , widely used by thousands of
developers around the world to develop I/O intensive web applications
like video streaming sites, single-page applications, and other web
applications.
• 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
Why Node.js?
Node.js uses asynchronous programming!
A common task for a web server can be to open a file on the server and
return the content to the client.
Here is how Node.js handles a file request:
• Sends the task to the computer's file system.
• Ready to handle the next request.
• When the file system has opened and read the file, the server returns the
content to the client.
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.
Download Node.js
The official Node.js website has installation instructions for
Node.js: https://nodejs.org
Examples of Node.js Application
To create a basic Hello World application in Node.js, save the following
single line JavaScript as hello.js file.
console.log("Hello World");
Open a powershell (or command prompt) terminal in the folder in
which hello.js file is present, and enter the following command. The
"Hello World" message is displayed in the terminal.
PS D:nodejs> node hello.js
Hello World
Example
Create a Node.js file named "myfirst.js", and add the following code:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World!');
}).listen(8080);
Save the file on your computer: C:UsersYour Namemyfirst.js
The code tells the computer to write "Hello World!" if anyone (e.g. a
web browser) tries to access your computer on port 8080.
Initiate the Node.js File
C:UsersYour Name>node myfirst.js
If anyone tries to access your computer on port 8080, they will get a "Hello World!" message in
return!
Start your internet browser, and type in the address: http://localhost:8080
• The http module is imported to create a basic HTTP server.
• The HTTP module can create an HTTP server that listens to server ports and gives a response back
to the client.
• The createServer() method is used to handle incoming requests and send responses.
• The function passed into the The createServer() method, will be executed when someone tries to
access the computer on port 8080.
• The server listens on port 8080, and a message is displayed in the browser when accessed.
Example
// Import the http module
const http = require('http');
// Create a server
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type, 'text/html');
res.end('Welcome to the Node.js Tutorial');
});
// Listen on port 3000
server.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
Example:
http = require('node:http');
listener = function (request, response)
{ // Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/html
response.writeHead(200, {'Content-Type': 'text/html'});
// Send the response body as "Hello World"
response.end('<h2 style="text-align: center;">Hello World</h2>');
};
server = http.createServer(listener);
server.listen(3000);
// Console will print the message
console.log('Server running at http://127.0.0.1:3000/');
Run the above script from command line.
C:nodejs> node hello.js
Server running at http://127.0.0.1:3000/
Now open a browser, and enter http://127.0.0.1:3000/ as the URL.
The browser displays the Hello World message as desired.
Node.js Advantages
• Easy Scalability: Node.js compiles and executes JavaScript at lightning
speeds, making it highly scalable.
• Real-time Web Apps: Node.js enables real-time communication for chat,
gaming, social media updates, and more.
• Microservices: Node.js is lightweight and ideal for microservice
architectures.
• JavaScript Everywhere: Learn JavaScript once, and you can use it both for
front-end and back-end development.
• Efficient Data Streaming: Node.js efficiently handles I/O processes like
media transcoding during uploads.
• Event-Driven Architecture: Unlike traditional servers, Node.js handles
concurrent requests effectively.
• Strong Community Support: Node.js has an independent community
backing its development.

introduction to node js kndoendenendjndj

  • 1.
  • 2.
    Course Content • Node.jsIntroduction • Node.js Environment Setup • Node.js First Application • Node.js REPL Terminal • Node.js Command Line Options • Node.js Package Manager (NPM) • Node.js Callbacks Concept • Node.js Upload Files • Node.js Send an Email • Node.js Events
  • 3.
    • Node.js EventLoop • Node.js Event Emitter • Node.js Debugger • Node.js Global Objects • Node.js Console • Node.js Process • Node.js File System • Node.js Streams • Node.js Scaling Application • Node.js Packaging
  • 4.
    Grad system Mid TermExam 20 degree Project 10 degree Practical exam 10 degree Final exam 60 degree Reference Books - Learning Node by Shelley Powers - The Node.js Handbook by Flavio copes
  • 5.
    • What isNode.js? Node.js is not a programming language like Python, Java or C/C++. Node.js is a runtime, similar to Java virtual machine, that converts JavaScript code into machine code. It is , widely used by thousands of developers around the world to develop I/O intensive web applications like video streaming sites, single-page applications, and other web applications. • 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
  • 6.
    Why Node.js? Node.js usesasynchronous programming! A common task for a web server can be to open a file on the server and return the content to the client. Here is how Node.js handles a file request: • Sends the task to the computer's file system. • Ready to handle the next request. • When the file system has opened and read the file, the server returns the content to the client. 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.
  • 7.
    Download Node.js The officialNode.js website has installation instructions for Node.js: https://nodejs.org Examples of Node.js Application To create a basic Hello World application in Node.js, save the following single line JavaScript as hello.js file. console.log("Hello World"); Open a powershell (or command prompt) terminal in the folder in which hello.js file is present, and enter the following command. The "Hello World" message is displayed in the terminal. PS D:nodejs> node hello.js Hello World
  • 8.
    Example Create a Node.jsfile named "myfirst.js", and add the following code: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end('Hello World!'); }).listen(8080); Save the file on your computer: C:UsersYour Namemyfirst.js The code tells the computer to write "Hello World!" if anyone (e.g. a web browser) tries to access your computer on port 8080.
  • 9.
    Initiate the Node.jsFile C:UsersYour Name>node myfirst.js If anyone tries to access your computer on port 8080, they will get a "Hello World!" message in return! Start your internet browser, and type in the address: http://localhost:8080 • The http module is imported to create a basic HTTP server. • The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client. • The createServer() method is used to handle incoming requests and send responses. • The function passed into the The createServer() method, will be executed when someone tries to access the computer on port 8080. • The server listens on port 8080, and a message is displayed in the browser when accessed.
  • 10.
    Example // Import thehttp module const http = require('http'); // Create a server const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type, 'text/html'); res.end('Welcome to the Node.js Tutorial'); }); // Listen on port 3000 server.listen(3000, () => { console.log('Server is running on http://localhost:3000'); });
  • 11.
    Example: http = require('node:http'); listener= function (request, response) { // Send the HTTP header // HTTP Status: 200 : OK // Content Type: text/html response.writeHead(200, {'Content-Type': 'text/html'}); // Send the response body as "Hello World" response.end('<h2 style="text-align: center;">Hello World</h2>'); }; server = http.createServer(listener); server.listen(3000); // Console will print the message console.log('Server running at http://127.0.0.1:3000/');
  • 12.
    Run the abovescript from command line. C:nodejs> node hello.js Server running at http://127.0.0.1:3000/ Now open a browser, and enter http://127.0.0.1:3000/ as the URL. The browser displays the Hello World message as desired.
  • 13.
    Node.js Advantages • EasyScalability: Node.js compiles and executes JavaScript at lightning speeds, making it highly scalable. • Real-time Web Apps: Node.js enables real-time communication for chat, gaming, social media updates, and more. • Microservices: Node.js is lightweight and ideal for microservice architectures. • JavaScript Everywhere: Learn JavaScript once, and you can use it both for front-end and back-end development. • Efficient Data Streaming: Node.js efficiently handles I/O processes like media transcoding during uploads. • Event-Driven Architecture: Unlike traditional servers, Node.js handles concurrent requests effectively. • Strong Community Support: Node.js has an independent community backing its development.