Lesson 2 of 8Article14 minFREE
Modules, npm, and Project Setup
Modern Node supports ES Modules with import/export. CommonJS (require/module.exports) still exists in many legacy projects.
CommonJS and ES Modules
Modern Node supports ES Modules with import/export. CommonJS (require/module.exports) still exists in many legacy projects.
ES module export and import
// math.js
export function add(a, b) {
return a + b;
}
// app.js
import { add } from "./math.js";
console.log(add(5, 7));npm essentials
- npm init creates package metadata and scripts.
- npm install adds dependencies to package.json.
- Use scripts for repeatable commands (dev, test, lint).
- Keep dependencies updated and audited.
Project bootstrap
npm init -y
npm install express
npm install -D nodemon
npm pkg set type=module