Modules and tooling
Split code into files, share it with import and export, and run a real project with npm.
What you will be able to do
- Use named and default exports
- Install and script tools with npm
- Understand why a bundler helps
A module is a file with its own scope. Exports are the public surface; imports pull values in. Modern tooling installs packages and runs scripts consistently.
// math.js
export function add(a, b) {
return a + b;
}
export default function multiply(a, b) {
return a * b;
}// app.js
import multiply, { add } from "./math.js";
console.log(add(2, 3), multiply(2, 3));npm init -y
npm install --save-dev vite vitest
npm run dev
npm test| File | Job |
|---|---|
| package.json | Dependencies and scripts |
| node_modules/ | Installed packages (never commit) |
| vite.config.js | Dev server and build settings |
| .js modules | Your own code, imported by path |
Your turn
MediumSplit a helper into a module
Write a format.js module exporting a named formatScore and a default formatName, then import both in app.js.
JAVASCRIPT · starter
// format.js
// write two exports
// app.js
// import both and log a sampleCheck your understanding before moving on.
Knowledge checkQuestion 1
Which import reads the named export add from ./math.js?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.