Visit https://nodejs.org/en and download the compatible version for Windows.
For Linux/Mac OS visit and follow the instructions mentioned at https://github.com/nodesource/distributions.
Run the following commands to check if you've successfully installed Node.js or not.
node -v
node --version
node
- Create a file called
index.js
and add any JS-related code. Eg:console.log('Hello there!');
- Open the terminal in the same directory as the
index.js
file. - Run the following command to execute the
index.js
file.
node index.js
- The output in your terminal should be:
Hello there!
console.log("hello, world!")
const a = 10;
const b = 20;
console.log(a + b);
try {
const element = document.querySelector('#box');
} catch (error) {
console.log('Not in browser!')
}
The output of the above code will be:
hello, world!
30
Not in browser!
This is because Node.js is a runtime environment OUTSIDE of your browser! Access to the web apps does not exist simply because they're not part of the system.
- JavaScript Execution Context – How JS Works Behind The Scenes
- Web APIs | MDN
- Introduction to Node.js
- npm
- What is backend development?
- It's usecase.
- What we will learn in the upcoming sessions?
- What is Node.js? Installing Node.js.
- Checking if Node.js is installed.
- Differneces between Modules and Packages.
- A better explaination is here - https://stackoverflow.com/questions/20008442/difference-between-a-module-and-a-package-in-node-js
Notion Page: https://kunal-keshan.notion.site/Getting-Started-with-Backend-Node-af73a67815f6496482f21de4ae33b1e4?pvs=4 - Refer for additional information.