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 3: create first program in NodeJS
Let's get started by
creating the simplest Node.js application,
Welcome to First NodeJS Applicatio
code .
§ From the File Explorer toolbar, press the New File
button:
And name the file main.js
:
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
Post a Comment