What is NodeJs?

Node.js is a cross-platform, open-source JavaScript runtime environment that can run on Windows, Linux, Unix, macOS, and more

Javascript

V8 Engine, SpiderMonkey and MacEngine

JavaScript Engine

Most popular

Node JS

You can run JS outside of the browser with the help of C++ and JavaScript engine.

 

JavaScript can talk to native machine because of C++.

 

C++ is a native language which gives you access to machine level functionalities

Conclusion: What is Nodejs?

NodeJS is a Runtime env. for JavaScript

File System in NodeJS

const fs = require("fs");

// the execution continues without waiting for the file writing process to complete.
fs.writeFile('file.txt', 'Hello, asynchronous!', (err) => {
    if (err) {
        console.error('Error writing file asynchronously:', err);
    } else {
        console.log('File written asynchronously.');
    }
});


// The program execution halts until the file is completely written after the call
try {
    fs.writeFileSync('file.txt', 'Hello, synchronous!');
    console.log('File written synchronously.');
} catch (err) {
    console.error('Error writing file synchronously:', err);
}

Event Loop

Headers in HTTP

An HTTP header is a field of an HTTP request or response that passes additional context and metadata about the request or response.

 For example, when a client wants to access a secure resource, it includes an 'Authorization' header with an authentication token. The server then validates this token to grant access. In short, headers help ensure secure communication between client and server.

HTTP Request Methods

  1. GET: Used to request data from a specified resource. GET requests should only retrieve data and should not have any other effect on the server.

  2. POST: Used to submit data to be processed to a specified resource. POST requests may result in the creation of a new resource or the update of an existing one on the server.

  3. PUT: Similar to POST, but typically used for updating data on the server.

  4. DELETE: Used to delete a specified resource from the server.

What Is API?

An application programming interface is a way for two or more computer programs or components to communicate with each other. It is a type of software interface, offering a service to other pieces of software.

Structure of an API

Breakdown of a typical API endpoint URL

What is NodeJs?

By Syed Ali Haider Rizvi