Manage your learning questions and answers
Use res.json to serialize objects as JSON.
app.get("/health", (req, res) => res.json({ ok: true }));
Define a final error handler with four args (err, req, res, next).
app.use((err, req, res, next) => {
res.status(500).json({ error: "Internal error" });
});
Read configuration from .env in development and access via process.env.
require("dotenv").config();
const dbUrl = process.env.DATABASE_URL;
Middleware are functions that have access to req/res and next; used for auth, logging, validation, etc.
Use express(), define routes, and listen on a port.
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('OK'));
app.listen(3000);
The event loop processes queued callbacks and enables non-blocking I/O in Node.js.