A minimal Express app demonstrating two core response methods:
res.send()— the generalist (HTML, text, etc.)res.json()— the specialist (APIs)
- Node.js
- npm
Check:
node -v
npm -vnpm installnpm startOpen:
http://localhost:3000/
You’ll get an HTML response (and your browser will render it).
Open:
http://localhost:3000/data
You’ll get JSON:
{ "status": "loaded", "cargo": ["box1", "box2"] }npm run watchStop with:
Ctrl + C
- flexible: can send HTML, text, buffers, etc.
- Express will infer a Content-Type (often
text/htmlfor strings)
- preferred for APIs
- sets
Content-Type: application/json - stringifies objects automatically
.
├── app.js
├── package.json
└── README.mdNode2Know-LEARN-1.0