🟢 Getting Started with Node.js

  



Node.js, one of the most used tools for developing and creating web applications (and not only) in the last decade. 

Let's discover in this article the basics of this now indispensable tool!

🔗 Do you like Techelopment? Check out the website for all the details!

✅ What is Node.js?

Node.js is a JavaScript runtime built on Chrome's V8 engine that allows you to run JavaScript code outside the browser. It’s widely used for building server-side applications, command-line tools, microservices, and more.

  • It is event-driven and non-blocking, ideal for I/O-heavy operations.
  • Perfect for building APIs, backend apps, bots, CLI tools, etc.

💾 Installing Node.js Locally

🔹 1. Go to the official website

👉 https://nodejs.org

🔹 2. Choose your version

  • LTS (Long Term Support): Recommended for most users, stable.
  • Current: Latest features, but less stable.

🔹 3. Install Node.js

Windows / macOS:

  1. Open the downloaded file (.msi or .pkg).
  2. Follow the setup wizard.
  3. Make sure the option to install npm is selected.

Linux (Ubuntu/Debian):

sudo apt update
sudo apt install nodejs npm

Or with nvm (Node Version Manager):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts

🔍 Verifying the Installation

✔️ Check Node.js version

node -v

✔️ Example output: v18.19.0

✔️ Check npm version

npm -v

✔️ Example output: 9.2.0


📦 What is npm?

npm stands for Node Package Manager. It's the official package manager for Node.js.

With npm, you can:

  • Install JavaScript libraries and frameworks (e.g., express, react)
  • Manage project dependencies with package.json
  • Publish your own packages on npmjs.com

Example: to install a package like Express:

npm install express

🚀 First Example with Node.js

🔸 Basic Script

  1. Create a file named hello.js
  2. Write the following code:
// hello.js
console.log("Hello from your first Node.js script!");

Run it with:

node hello.js

✅ Output: Hello from your first Node.js script!


🎁 Bonus: mini HTTP server

Here’s a more advanced example: a small HTTP server built with Node.js.

// server.js
const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/html' });
  res.end('Hello, this is my first Node.js server!\n');
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000');
});

Run with:

node server.js

🔗 Then open your browser and go to http://localhost:3000

🎉 Congratulations! You’ve just installed Node.js, understood what npm is, and run your first script. Have fun 😊!



Follow me #techelopment

Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment