Npm packages
| Npm install | |
| Import them | |
| @types concept | |
| Pin versions |
Npm install
Packages are folders of reusable code published with a name and a version number. Your project records each choice in package.json so every machine installs the same set.
Installing adds the files to a local folder and updates that record for you. From then on the dependency is part of the project, not a copy pasted snippet hidden in one file.
Import them
Installed code stays dormant until you import it by name. Named imports make the source visible at the top of the file, so readers see exactly which helper comes from which package.
Keep imports at the top and use clear local names. Short modules with explicit imports are easier to move, test, and review than long files with hidden globals.
import { greet } from "greetlib";
const message: string = greet("Ada");
console.log(message);
@types concept
Many packages ship their own type declarations, so completion and checking work right after install. Older JavaScript libraries have no bundled types, which is where separate type packages help.
A type package contains only declarations for the matching library. It does not change runtime behavior, it only teaches the checker the shapes of functions, options, and return values.
Pin versions
Versions move forward, and new releases can change behavior. Pinning records an exact version so builds stay identical today, tomorrow, and on a teammate machine.
Update versions on purpose, one package at a time, then run checks again. Small deliberate upgrades are calmer than surprise changes during an unrelated task.
{
"name": "my-app",
"version": "1.0.0",
"dependencies": {
"greetlib": "1.4.2"
}
}
Next: Bundling concept
Article author: Arthur Isaev