Backend 01 - Node.js Basics


1. What is Node.js?
A JavaScript runtime environment.
Allows running JavaScript outside the browser (e.g., on servers).
Built on Chrome’s V8 JavaScript Engine.
Enables building fast, scalable network applications.
2. Who Created Node.js and Why?
Created by: Ryan Dahl
Released in: 2009 (initial work started in 2007)
Reason:
Traditional servers like Apache handled concurrent requests inefficiently.
Node.js was designed for non-blocking, event-driven, real-time applications.
3. Installing Node.js
Download from https://nodejs.org
Choose:
LTS (Long Term Support): Stable version recommended for most users.
Current: Latest features but less stable.
4. Running JavaScript Files with Node
Use the terminal/command prompt:
node filename.js
Node provides its own runtime environment with built-in APIs like:
fs
(file system)http
(server creation)path
, etc.
5. Packages in Node.js
Packages are reusable libraries or tools.
Installed using npm (Node Package Manager).
Example:
npm install cat-me
6. Packages vs Modules
Feature | Package | Module |
Definition | Third-party tools/libraries | Built-in features in Node.js |
Source | Installed via npm | Comes with Node.js |
Examples | express , cat-me | http , fs , path |
7. Installing and Using a Package (e.g., cat-me)
Installation:
npm install cat-me
Usage in your code:
const catMe = require("cat-me"); console.log(catMe());
8. HTTP Module in Node.js
Built-in module to create servers.
No installation required.
Enables handling HTTP requests and responses.
9. Creating a Simple Server with HTTP Module
// http -> it is a module. didn't require to install
//express -> it is a package. reuired to install
const http = require('http')
const server = http.createServer((req,res)=>{
res.end("Hello! Code Subtle") //printing message to server
}) //for creating the server
//for starting the server
server.listen(3000,()=>{
console.log("server is running");
})
Subscribe to my newsletter
Read articles from Code Subtle directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Code Subtle
Code Subtle
At Code Subtle, we empower aspiring web developers through personalized mentorship and engaging learning resources. Our community bridges the gap between theory and practice, guiding students from basics to advanced concepts. We offer expert mentorship and write interactive, user-friendly articles on all aspects of web development. Join us to learn, grow, and build your future in tech!