- Modules split code into separate files. Each module has its own scope.
exportshares things from a module.import { name } from "./file.js"brings them in. Each module can have oneexport default, imported without braces.- In the browser, use
<script type="module">, served from a web server (like Live Server). - Node.js runs JavaScript outside the browser, with extra powers: files, servers, databases, command-line tools.
- Enable
import/exportin Node with"type": "module"inpackage.json(or.mjsfiles). Older code usesrequire(CommonJS). node:fs/promisesgives youreadFileandwriteFile.process.argv.slice(2)gives you command-line arguments (as strings).- npm installs packages from the npm registry.
npm init -ycreatespackage.json.npm install nameadds a dependency tonode_modules. Never share or editnode_modules. - npm scripts in
package.jsoncreate shortcut commands likenpm startandnpm test. - Automated tests check your code for you. Node has a built-in runner:
node --testwithnode:testandnode:assert. - The pro toolbox: Git/GitHub, Prettier, ESLint, TypeScript, frameworks (React, Vue, Svelte, Angular), build tools (Vite) and hosting (GitHub Pages, Netlify, Vercel).
Reading is step one
CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.