Skip to content

Latest commit

 

History

History

Session 1 - Getting Started with Backend (Node)

Session 1 - Getting Started with Backend (Node)

Session 1

Installing Node.js

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.

Checking if Node.js is Installed

Run the following commands to check if you've successfully installed Node.js or not.

node -v
node --version

Work with Node.js in Your Terminal directly

node

Run a JavaScript file using 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!

WebAPIs are not accessible in Node.js Environment!

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.

Resources Used

  1. JavaScript Execution Context – How JS Works Behind The Scenes
  2. Web APIs | MDN
  3. Introduction to Node.js
  4. npm

What we covered?

Notion Page: https://kunal-keshan.notion.site/Getting-Started-with-Backend-Node-af73a67815f6496482f21de4ae33b1e4?pvs=4 - Refer for additional information.