Skip to main content

Command Palette

Search for a command to run...

Backend 01 - Node.js Basics

in this article, we're going to learn the basics of node.js

Updated
2 min readView as Markdown
Backend  01 - Node.js Basics
C

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!

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

FeaturePackageModule
DefinitionThird-party tools/librariesBuilt-in features in Node.js
SourceInstalled via npmComes with Node.js
Examplesexpress, cat-mehttp, 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");
})

Backend Mastery

Part 1 of 5

In this series, we will learn about Backend Technologies like Express, MongoDB, and Node.js in detail.

Up next

Backend 02 - Express and API in Node.js

Learning how to create Express Server and API calls on it