Node.js quick reference
Commands and Express essentials on one page.
| Code | Purpose |
|---|---|
npm install name | Add a package |
npm install -D name | Add a development-only package |
npm run dev | Run a script from package.json |
process.env.PORT | Read an environment variable |
req.params.id | A value from the URL path |
req.query.page | A value after ? in the URL |
req.body | Parsed JSON from the request |
res.json(x) | Send JSON |
res.status(404) | Set the status code |
app.use(fn) | Add middleware |