Getting Started with Node Js

Being in love with coding, I'm looking for opportunities to utilize and grow my technical abilities as a programmer (full stack developer, frontend or backend )
Intro to Node Js π₯
Node Js is a open source run-time environment which uses Chrome V8 Javascript on the Server; created by Ryan Dahl in 2009.
It has capability to run in various platform (MacOs, Windows, Linux). The main purpose of introducing Node js was to build a real-time application with push capability.
π¨ If you want to download Node js in you operating system you can checkout the official documentation and follow the instruction source:Download Node Js
β The main benefits of Node js are:
Node helps to run javascript directly in the terminal
Due to the node run time, we are able to interact with operating system features from javascript like; access to file, add new file and read the file
Thanks to the node js due to which now we can make desktop application(Electron) and mobile application(react-native) as well.
Node.js provides developers a comprehensive tool for working in the non-blocking, event-driven I/O paradigm
Node Js can be stateless(exposes stateless entities such as; class, objects & methods) or stateful (exposes a stateful instances of an object such as database connection & an instance object of third party service).
Image-source: GeeksForGeeks
Is Node Js is a synchronous or asynchronous π€?
- Actually, the question should be is Javascript inside node is synchronous or asynchronous, so the answer is Javascript is still
synchronousbut it can support asynchronous task because of event queue and event loop.
What is the use of Node js?
- Node Js helps to build the real-time web application employing push technology over WebSocket. It also helps in two-way connection where both the client and server can initiate communication, allowing them to exchange data more freely.
π Tips: In node Js settimeout function working is same but the return type is different
Browser: Number
Node: Object
What is V8 Engine π ?
- V8 is Googleβs open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others. πsource: V8 Engine
It is a C++-based open-source JavaScript engine developed by Google which translates JavaScript into executable code i.e. machine code.
Initially, it was created for Google Chrome and Chromium web browsers to enhance the performance of JavaScript execution but latter it executes the js code outside the browser , enabling server-side scripting
To achieve faster JavaScript execution speeds, V8 translates JS code to more efficient machine code instead of using an interpreter. Most modern JavaScript engines like SpiderMonkey or Rhino follow the same approach, but what makes V8 stand out is that it does not produce any intermediate code.
It is a single threaded execution engine. Itβs built to run exactly one thread per JavaScript execution context.
You can actually run two V8 engines in the same process β e.g. web-workers, but they wonβt share any variables or context like real threads. This doesnβt mean V8 is running on a single thread, but it does mean it provides a JavaScript flow of a single thread.

What is Express Js ?
- Express is a one of the most popular node js framework which helps to design and build web application quickly and easily in the server-side into a more organized MVC architecture.
Generally, it is a framework which means the code is already written for programmer to work with. With the help of express we can build single page, multi- page applications
Why Express Js is popular π€?
- Building web application is easy and fast
- It reduces the amount of bugs you will write
- Helps to build a REST API Server
- Allows you to define routes of your application based on HTTP methods and URLs.
- Easy to connect with databases such as MongoDB, Redis, MySQL
π¨. Installing Express in your project is very easy you just copy the below code
npm install express
creating an express server
Step: 1 ==> Make a
folderand open it in an IDE (Vs code) and make a file nameapp.jsStep: 2 ==> Open the terminal and write
npm init -y{ you can see a package.json file}Step: 3 ==> You can simply write
npm install expressto install the express on your project folder {node_module folder will appear inside you project folder}Step: 4 ==> If you want you can install Nodemon by simply typing
npm i nodemonin the terminal {The purpose of this package is to watch for any changes in our files and restart the server instead of us having to do that manually ourselves.}Step: 5 ==> Inside the
package.jsonfile add a start script with nodemon app.js
"start" : "nodemon app.js"
πNow your package.json file looks like this π

- Step: 6 ==> Open app.js file and copy the snippet
const express = require('express')
const app = express()
const port = 3000
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
π In the above code snippet we are importing express(using Common Js module) and storing in express variable and initialising the express() and storing in app variable. i'm using port 3000 and we are listening the port using app.listen() which takes a callback function and simply printing in the console .
Step: 7 ==>After that you can simply add a request and your final code snippet will looks like this π

Step:8 ==> Again, in your terminal write
npm startand your terminal look like this π
Congratulation !! π you are almost done... at last go to your browser and write and
Hello worldwill appear
http://localhost:3000/
β€οΈ Thank you for reading and hopefully I have enticed you to learn more and experiment with Node.js and Express.js.




