Node.js-Introduction

Spread the love

Key Points – Node.JS

  • Open Source
  • Cross Platform
  • Javascript Runtime Environment
  • Execute in Server Side
  • Runs on V8 Engine
  • Written in (JS) + (C++)

Version History

1 1
2 3

Why Node.JS Special?

Let’s get Idea of Why we use Node.JS

Javascript Everywhere

Allowing web application development to unify around a single programming language, rather than rely on a different language for writing server side scripts

Server Side JS

Javascript used primarily for client-side scripting, Node.js enables JavaScript to be used for server-side scripting

Key Features

Threading

Node.js operates on a single thread, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections without incurring the cost of thread context switching.

V8

V8 is the JavaScript execution engine built for Google Chrome and open-sourced by Google in 2008. Written in C++, V8 compiles JavaScript source code to native machine code instead of interpreting it in real time.

Package management

npm is the pre-installed package manager for the Node.js server platform. It is used to install Node.js programs from the npm registry, organizing the installation and management of third-party Node.js programs.

 

Unified API

Node.js can be combined with a browser, a database supporting JSON data. With the adaptation of what were essentially server-side development patterns such as MVC, MVP, MVVM, etc

Event loop

Node.js registers itself with the operating system in order to be notified when a connection is made, and the operating system will issue a callback.

 

Who Uses Node.JS?

3 2

PHP Way & Node.JS Way

4 1

What Node.JS Can Do?

  • 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

Getting Started !

var http = require(‘http’);

http.createServer(function (req, res) {
    res.writeHead(200, {‘Content-Type’: ‘text/html’});
    res.end(‘Hello World!’);
}).listen(8080);

Type This Code and Save it As myfirst.js in Known Location,

Then Open Command Line Tool and Navigate to the Location that we saved our js File.

D:/first>node myfirst.js

Check node version and npm version

1 2

Open Note pad and make Hello world application and Run . 

2 4

Run on server 8080

3 3

Get a JSON output from node application

4 2

Get a XML output from node application

5 1

Make a node functions

6 2

Create external html file

7 1

Read external file from nodejs

8 1
9 1

Node module install using rpm

10 1

Testing with server-Upper case letter

11 3

Node.JS Folder structure 

12 1

Module structure

13 2

Mysql install

14 1

Connect to Mysql data base and retrieve data as JSON format

15 1
16 1