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


www.CodeNirvana.in

Powered by Blogger.

About

Site Links

Popular Posts

Translate

Total Pageviews