import
`import` brings into your file what another module exports, by name.
Each file is a module with its own scope. What another file marks with export you can bring in with import.
Read it like this: import { greet } from "./greet"; means "from the module ./greet, give me the export named greet". The braces ask for named exports, and the name must match exactly.
The path after from is called a specifier. If it starts with ./ or ../, it's your own file. If it starts with node:, it's a Node built-in module, like node:path or node:crypto.
Imports go at the top of the file, at top level, never inside a function or an if. That way Node and TypeScript know every dependency before anything runs, and tsc can check that each name exists and has the right type.
Reach for it when: you need something defined in another file or in a Node built-in module.
Examples
Common mistake
import { Basename } from "node:path";
console.log(Basename("/tmp/a.txt"));Why: Imported names are case-sensitive. `node:path` exports `basename`, not `Basename`, so tsc rejects it.
How to write it: Write the name exactly as it's exported: import { basename } from "node:path";.
