esc
Type to search across all notes

JavaScript Packages

This note includes some important concepts and how-to guides related to JavaScript packages.

What is a JavaScript Package?

Prehistory

A JavaScript package is a concept introduced with Node.js and its package manager, npm. Before Node.js/npm, there was no standardized “package” system in JavaScript. Developers shared reusable code as libraries or frameworks, often distributed as standalone files or via CDNs.

To manage dependencies and organize code, tools like RequireJS (for module loading), Browserify (for bundling CommonJS modules for the browser), and Grunt/Gulp (for automating build tasks) were commonly used. These tools helped combine scripts, handle dependencies, and automate repetitive tasks, but lacked the unified ecosystem and registry that npm provides for packages today.

Create a JavaScript package

A basic JavaScript package structure looks like this:

my-package/
├── package.json       # Metadata and config (required)
├── README.md          # Project description (recommended)
├── LICENSE            # License info (recommended)
├── index.js           # Main JavaScript entry point
└── (optional files)
├── lib/               # Additional source files
├── tests/             # Tests folder
└── .gitignore         # Git ignore rules

package.json is the core of any JavaScript package. It contains essential metadata, configuration, and dependency information that npm and other tools use to manage, install, and publish your package. Without package.json, your project cannot be recognized as a package by npm.

More information can be found in the npm package.json documentation.