TGViewer
Web Development Web Development @web_dev_bds Β· 4.43K subscribers
Post #725 676
βœ… Node.js Basics You Should Know 🌐

Node.js lets you run JavaScript on the server side, making it great for building fast, scalable backend applications. πŸš€

1️⃣ What is Node.js?
Node.js is a runtime built on Chrome's V8 JavaScript engine. It enables running JS outside the browser, mainly for backend development. πŸ–₯️

2️⃣ Why Use Node.js?
- Fast & non-blocking (asynchronous) ⚑
- Huge npm ecosystem πŸ“¦
- Same language for frontend & backend πŸ”„
- Ideal for APIs, real-time apps, microservices πŸ’¬

3️⃣ Core Concepts:
- Modules: Reusable code blocks (e.g., fs, http, custom modules) 🧩
- Event Loop: Handles async operations ⏳
- Callbacks & Promises: For non-blocking code 🀝

4️⃣ Basic Server Example:
const http = require('http');

http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello, Node.js!');
}).listen(3000); // Server listening on port 3000


5️⃣ npm (Node Package Manager):
Install libraries like Express, Axios, etc.
npm init
npm install express


6️⃣ Express.js (Popular Framework):
const express = require('express');
const app = express();

app.get('/', (req, res) => res.send('Hello World!'));
app.listen(3000, () => console.log('Server running on port 3000'));


7️⃣ Working with JSON & APIs:
app.use(express.json()); // Middleware to parse JSON body
app.post('/data', (req, res) => {
  console.log(req.body); // Access JSON data from request body
  res.send('Received!');
});


8️⃣ File System Module (fs):
const fs = require('fs');
fs.readFile('file.txt', 'utf8', (err, data) => {
  if (err) throw err;
  console.log(data); // Content of file.txt
});


9️⃣ Middleware in Express:
Functions that run before reaching the route handler.
app.use((req, res, next) => {
  console.log('Request received at:', new Date());
  next(); // Pass control to the next middleware/route handler
});


πŸ”Ÿ Real-World Use Cases:
- REST APIs πŸ“Š
- Real-time apps (chat, notifications) πŸ’¬
- Microservices πŸ—οΈ
- Backend for web/mobile apps πŸ“±

πŸ’‘ Tip: Once you're confident, explore MongoDB, JWT auth, and deployment with platforms like Vercel or Render.

πŸ’¬ Tap ❀️ for more!
  • ❀ 3
More from @web_dev_bds
  1. Oct 16, 2026πŸ“•Random React Tip: If you want to quickly log things from JSX (we've all been there), you…
  2. Oct 15, 2026Websites to Learn Every Technology
  3. Oct 13, 2026Docker vs Kubernetes
  4. Oct 12, 2026Post #1054
  5. Oct 11, 2026CSS Tip Stop centring tooltips with πšπš›πšŠπš—πšœπš•πšŠπšπšŽ: -𝟻𝟢%. near the edge of the scree…
  6. Oct 9, 2026JavaScript CheatSheet
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’