📌 What is Express.js?

Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications.

🚀 Why Use Express?


🌍 Environment Variables

Environment variables are global variables that are specific to the environment in which the app is running (e.g., development, production). These are typically used to set configuration values like ports, API keys, etc.

var port = process.env.PORT || 3000;
app.listen(port);

⚙️ Creating a Simple Server in Express

Express makes it easier to create a server and handle HTTP methods.

var express = require('express');
var app = express();
var port = process.env.PORT || 3000;

app.get('/', function (req, res) {
  res.send('Hello World!');
});

app.get('/api', function(req, res) {
  res.json({'API': 'Hello World!'});
});

app.listen(port);

🔗 Routing with Parameters

You can define dynamic variables in routes like this:

app.get('/person/:id', function(req, res) {
  res.send('Person with id: ' + req.params.id);
});