Featured

    Featured Posts

Setup Environment to run NodeJS code

 

Setup Environment to run NodeJS code

  §  Node.js is a platform for building fast and scalable server applications using JavaScript. Node.js is the runtime and npm is the Package Manager for Node.js modules.

  §  Visual Studio Code has support for the JavaScript and TypeScript languages out-of-the-box as well as Node.js debugging. However, to run a Node.js application, you will need to install the Node.js runtime on your machine.

Steps to prepare first application in nodejs

Step 1: Install the latest version of node.

§  Here is the link to download and install the latest version

https://nodejs.org/en/download/

§  To verify the version of NODE and NPM you have, execute the following 2 commands using the command prompt window. Make sure you are running the command prompt as an administrator.

node -v

npm -v

  §  If you already have NODE and NPM installed and if you want to upgrade to the latest version simply download and run the installer again, and it will automatically update NODE and NPM to the latest version.

Step 2: Install Visual Stdio
Download and install Visual Studio Code
https://code.visualstudio.com/download

Step 3: create first program in NodeJS

Let's get started by creating the simplest Node.js application,

Welcome to First NodeJS Applicatio

    §  Create an empty folder called " myfirstnodejsapp ", navigate into and open VS Code:
           mkdir myfirstnodejsapp
          cd mynodejsapp

    §  Once you are in the project directory, execute the following command to open the project with Visual Studio Code, by executing the following command from the windows command prompt.

            code .

          

   §  From the File Explorer toolbar, press the New File button:


And name the file main.js:

§  By using the .js file extension, VS Code interprets this file as JavaScript and will evaluate the contents with the JavaScript language service.
§  Create a simple string variable in main.js and send the contents of the string to the console:
var msg = 'Welcome to First NodeJS Application';
console.log(msg);  


Integrated Terminal

§  VS Code has an integrated terminal which you can use to run shell commands. You can run Node.js directly from there and avoid switching out of VS Code while running command-line tools.

§  View > Terminal (Ctrl+` with the backtick character) will open the integrated terminal and you can run node app.js there:

Execute the first program in NodeJS

§  Go to VSCode Terminal and type following command to run NodeJS application.

node filename


NodeJS Introduction

 NodeJS Introduction

  §  In this tutorial we will discuss NodeJS will help you learn the essentials of Node.js starting from the basics to an advanced level.

Prerequisites

  §  Before proceeding with this tutorial, you should have a Basic knowledge of HTML, JavaScript and web application is recommended.

WEB APPLICATION REQUIREMENTS :
ü Browser software.
ü Technology to develop client side.
ü Technology to develop server side.
ü User software.
ü Database software.

     WEB Server Software :

  §  Web server software is special piece of s/w (or) special s/w which can manages the web applications and web resources we executes this web resources automatically or dynamically whenever your requesting .


Responsibilities of web server :
§  It accepts all client http requests.
§  After accepting the request it passes your request to appropriate web resources of web application.
§  Web server proceeds your request and produce result.
§  Finally it will Gives resultant out put back to the client.

 

 What is NodeJS?

§  NodeJS is the Server side scripting language.

§  By using NodeJS, we can develop Http Servers.

§  We can develop Node application by using JavaScript.

§  Node follows Event Driven Model.

§  Node supports the modules. Predefined modules & custom modules.


 Features of NodeJS
§  NodeJS uses an event driven programming paradigm.
§  Event driving paradigm means that if we do any work, we need to raise an event for that work.
§  In this type of, flow of execution is determined by the events like user clicks or other programming threads or query result from database.
§  Events are handled by event handlers or event callbacks.
§  Event callback is nothing it is a function that is invoked when something significant happens like when click event is performed by user or the result of database query is available.
§  Non-blocking I/O model
§  When we send a request to the server and have to fetch some data, what we do is first our request goes to the server, and then the server sends the request database, searches its expected results and then gives it back to you again.
§  When the second request comes, the server accepts it, processes it and then gives a response. During this time, if two to three requests come at the same time, first it checks request on the priority basis that the request which come first that request serves first until first request has not been completed till second request has to wait.ie. The request will remain pending in queue. Once first request gives the result then second request process.
§  When we are sending a request in php/java/.net technology to the server Remaining request is blocked until the first request gets the result (second, third). This request remains blocked until the result of the first request is not gets.

 What happened when you send a request in NodeJS

§  Whenever we send a request in NodeJS. NodeJS listen the first request and after listing the first request NodeJS becomes ready to listing another request at the same time i.e. NodeJS  does not wait for I/O completion of the first request.

§  A NodeJS uses non-blocking I/O operations. This allows a single process to serve multiple requests at the same time. Instead of process being blocked and waiting for single I/O operation to complete, this waiting time is used to serve other requests. All Node.js libraries and the Node core api offer non-blocking operations with few minor exceptions.


  What difference between NodeJs and other server side web technology just

 like(Java/PHP/.Net)

Java |PHP |.Net

§  Browser Sends request to server.

§  Server sends request to database or file.

§  While the database or file is being read/written, the server simply waits until the operation is completed.

§  After completion of database/file operation, the content is sent to the browser.

§  The server is ready to receive next request.


NodeJS

§  Browser Sends request to server.

§  Server sends request to database or file.

§  Server will not wait until the completion of database operation/file operation simply   it receives another request starts its processing.

§  After completion of database/file operation, the content is sent to the browser.

 

 


www.CodeNirvana.in

Powered by Blogger.

About

Site Links

Popular Posts

Translate

Total Pageviews