Node and Express are the runtime and HTTP framework for your API. Topics here cover bootstrapping the app, parsing JSON bodies, and structured logging—everything that runs before a route handler executes. Master this layer first so later routers and controllers plug into a consistent foundation.

How to use environment variables — Basic

Read configuration from process.env (often with dotenv) for ports, secrets, and log levels.
Learn: Twelve-factor apps store config in the environment: ports, database URLs, API keys, and log levels. Never commit secrets. Use `.env` locally with dotenv; in production the host injects variables.

Supplementary examples

Load dotenv at startup

require("dotenv").config();

const PORT = process.env.PORT || 5000;
const DATABASE_URL = process.env.DATABASE_URL;

Fail fast if required env is missing

if (!process.env.DATABASE_URL) {
  throw new Error("DATABASE_URL must be set");
}

Course example

const express = require('express');
const cors = require('cors');
const app = express();
const router = express.Router();
const PORT = process.env.PORT || 5001;
router.get('/', cors(), (req, res) => {
res.json({ message: 'Hello Render!' });
});
app.use('/', router);
app.listen(PORT, () => {
console.log(`Server running on ${PORT} `);
});
module.exports = app;

Additional references & examples

← All Project configuration · Node / Express