Zero-Dependency JavaScript: Replace Common npm Packages With Built-in Features
On this page
- Why fewer dependencies matter
- Replacements you can use today
- HTTP requests: fetch instead of axios
- Deep copies: structuredClone
- Dates, numbers and currency: Intl
- IDs, URLs and query strings
- Node.js tooling without packages
- Small utilities you don’t need a package for
- When a dependency is the right choice
- Auditing an existing project
- Browser features that replace UI libraries
- Frequently asked questions
- Oh hi there 👋It’s nice to meet you.
- Sign up to receive awesome content in your inbox.
A fresh JavaScript project can pull in hundreds of packages before you write a line of code. Each one is code written by someone else that you ship, update and trust. Many of the most popular packages were created years ago to fill gaps in the language and platform, and many of those gaps have since closed. Zero-dependency JavaScript means preferring the features built into browsers and Node.js, and adding a package only when it clearly earns its place.
This guide explains why that matters, then gives a practical list of packages you can replace with built-in features today, with before-and-after code.
Why fewer dependencies matter
- Security. Every package, and every package it depends on, can contain vulnerabilities or be taken over by an attacker. Supply-chain attacks on npm packages are a real and recurring problem. Code you don’t install can’t be compromised.
- Bundle size. In the browser, every kilobyte of JavaScript must be downloaded, parsed and run, which hits users on slow phones and mobile data hardest.
- Maintenance. Packages get abandoned, change APIs in major versions, and trigger
npm auditwarnings you must investigate. Built-in features are maintained by browser and Node.js teams and stay stable for years. - Install speed. Fewer packages mean faster
npm ciin CI and on servers. - Learning. Knowing the platform itself makes you a better developer than knowing only wrappers around it.
Replacements you can use today
| Package | Built-in replacement | Where |
|---|---|---|
axios, node-fetch, request |
fetch |
Browsers, Node.js 18+ |
lodash.clonedeep |
structuredClone() |
Browsers, Node.js 17+ |
moment (formatting) |
Intl.DateTimeFormat, Intl.RelativeTimeFormat |
Browsers, Node.js |
numeral, currency formatters |
Intl.NumberFormat |
Browsers, Node.js |
uuid (v4) |
crypto.randomUUID() |
Secure browser pages, Node.js |
qs, query-string (simple cases) |
URLSearchParams, URL |
Browsers, Node.js |
dotenv |
node --env-file=.env |
Node.js 20.6+ |
nodemon |
node --watch |
Node.js 18.11+ (stable in 22) |
mocha, jest (small projects) |
node:test and node:assert |
Node.js 18+ |
chalk (simple colors) |
util.styleText() |
Recent Node.js versions |
yargs, minimist (simple CLIs) |
util.parseArgs() |
Node.js 18.3+ |
rimraf, mkdirp, fs-extra (basics) |
fs.rm({ recursive }), fs.mkdir({ recursive }), fs.cp() |
Node.js 16.7+ |
lodash.groupby |
Object.groupBy() |
Recent browsers, Node.js 21+ |
Check the minimum versions against the browsers and Node.js versions your users and servers actually run. Everything in this table works in current versions.
HTTP requests: fetch instead of axios
// a tiny wrapper covers what most apps used axios for
async function http(url, { method = 'GET', body, headers, timeout = 8000 } = {}) {
const res = await fetch(url, {
method,
headers: { 'Content-Type': 'application/json', ...headers },
body: body ? JSON.stringify(body) : undefined,
signal: AbortSignal.timeout(timeout),
});
const data = res.headers.get('content-type')?.includes('application/json') ? await res.json() : await res.text();
if (!res.ok) throw Object.assign(new Error(`HTTP ${res.status}`), { status: res.status, data });
return data;
}
const user = await http('/api/users/me');
await http('/api/orders', { method: 'POST', body: { productId: 'p1', qty: 2 } });
Twelve lines give you JSON handling, timeouts and errors on non-2xx responses, the main reasons people reached for axios. More patterns are in how to fetch data from an API in Express.
Deep copies: structuredClone
const original = { name: 'Cart', items: [{ id: 1, qty: 2 }], updated: new Date() };
const copy = structuredClone(original);
copy.items[0].qty = 5;
console.log(original.items[0].qty); // 2: the original is untouched
console.log(copy.updated instanceof Date); // true: dates survive, unlike JSON.parse(JSON.stringify())
structuredClone handles nested objects, arrays, dates, maps, sets and even circular references. It can’t copy functions or DOM nodes, which is rarely a problem for data.
Dates, numbers and currency: Intl
const date = new Date('2026-11-11T10:30:00Z');
new Intl.DateTimeFormat('en-IN', { dateStyle: 'long', timeZone: 'Asia/Kolkata' }).format(date);
// "11 November 2026"
new Intl.RelativeTimeFormat('en', { numeric: 'auto' }).format(-1, 'day');
// "yesterday"
new Intl.NumberFormat('en-IN', { style: 'currency', currency: 'INR' }).format(1249999.5);
// "₹12,49,999.50" (Indian digit grouping, built in)
new Intl.NumberFormat('en', { notation: 'compact' }).format(1530000);
// "1.5M"
Intl understands locales, so Indian lakh and crore grouping, other languages and time zones work without extra packages. Moment.js itself is in maintenance mode and recommends alternatives. For heavy date arithmetic, a small library such as date-fns or the upcoming Temporal API is still worth it, but formatting alone never needs one.
IDs, URLs and query strings
crypto.randomUUID(); // "3b241101-e2bb-4255-8caf-4136c566a962"
const url = new URL('https://shop.example.com/search');
url.searchParams.set('q', 'mern stack');
url.searchParams.set('page', '2');
url.toString(); // ".../search?q=mern+stack&page=2"
const params = new URLSearchParams(location.search);
const page = Number(params.get('page') ?? 1);
In the browser, crypto.randomUUID() is available on secure pages (HTTPS or localhost). URLSearchParams handles encoding correctly, which is a common source of bugs when building query strings by hand. For nested query objects, a package such as qs is still useful.
Node.js tooling without packages
{
"scripts": {
"dev": "node --watch --env-file=.env server.js",
"start": "node --env-file=.env server.js",
"test": "node --test"
}
}
That replaces nodemon, dotenv and a test framework for many small and medium projects. A simple command-line tool needs no argument parser either:
import { parseArgs, styleText } from 'node:util';
const { values } = parseArgs({
options: {
port: { type: 'string', short: 'p', default: '3000' },
verbose: { type: 'boolean', short: 'v' },
},
});
console.log(styleText('green', `Starting on port ${values.port}`));
Small utilities you don’t need a package for
// group items by a key
const byCity = Object.groupBy(users, (u) => u.city);
// last item, without length - 1
const last = items.at(-1);
// remove duplicates
const unique = [...new Set(tags)];
// wait
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// debounce: see the debouncing guide for a full version
const debounce = (fn, ms) => { let t; return (...a) => { clearTimeout(t); t = setTimeout(() => fn(...a), ms); }; };
Many tiny npm packages contain just one of these lines. The famous “left-pad” incident, where removing an 11-line package broke builds worldwide, is a reminder that small helpers are often better written yourself. The full debounce and throttle guide is in debouncing and throttling in JavaScript.
When a dependency is the right choice
Zero dependencies is a direction, not a rule. Use a well-maintained package when the problem is genuinely hard or risky to solve yourself:
- Security-critical code: password hashing (
bcrypt,argon2), JWT handling, HTML sanitizing. Never write your own. - Complex domains: rich text editors, PDF generation, charts, date arithmetic across time zones.
- Frameworks: React, Express and database drivers do far more than you could reasonably rebuild.
- Validation: a schema library like Zod saves hundreds of lines of error-prone checks.
Before adding a package, ask: does the platform already do this? Is the package actively maintained? How many dependencies does it bring in? You can check with npm view package-name dependencies before installing, and tools like bundle size checkers show the cost in kilobytes.
Auditing an existing project
- Run
npx depcheckto find packages nothing imports anymore, and remove them. - List your direct dependencies and check each against the replacement table above.
- Replace one package at a time and run your tests after each change.
- For frontend apps, measure the bundle before and after with a bundle visualizer, to see the real gain.
- Repeat every few months. Platforms keep adding features, so last year’s necessary package may be unnecessary now.
The npm cheat sheet covers the commands for auditing and cleaning dependencies.
Browser features that replace UI libraries
The same trend applies to user interface code. Several features that used to need a JavaScript library are now built into HTML and CSS:
- Modals: the
<dialog>element withshowModal()traps focus, closes with Escape and adds a backdrop, all accessibly and without a modal library. - Dropdowns and tooltips: the
popoverattribute shows and hides content on top of the page, with light-dismiss when clicking outside. - Accordions:
<details>and<summary>expand and collapse with no JavaScript at all. - Lazy loading:
loading="lazy"on images and iframes, orIntersectionObserverfor custom cases. - Carousels: CSS scroll snapping creates swipeable sliders with native scrolling.
- Form validation:
required,type="email",patternandminlengthgive instant feedback before any script runs.
<button popovertarget="menu">Account</button>
<div id="menu" popover>
<a href="/profile">Profile</a>
<a href="/logout">Log out</a>
</div>
That dropdown needs no JavaScript, works with the keyboard and closes when you click elsewhere. In React apps, these native elements can still be wrapped in your own components, so you get consistent styling without shipping a library for every widget.
Frequently asked questions
Is axios still worth using?
It can be, for features such as interceptors that many teams like, and for very old environments. For most new projects, built-in fetch with a small wrapper covers the same needs with no dependency.
Is Moment.js deprecated?
Moment.js is in maintenance mode, and its own documentation recommends alternatives for new projects. Use Intl for formatting and a modern library such as date-fns when you need date arithmetic.
Does zero-dependency mean no frameworks?
No. It means preferring built-in features for small tasks. Frameworks and well-maintained libraries for complex problems are still good choices.
How do I check how many dependencies a package has?
Run npm view package-name dependencies before installing, or npm ls --all in a project to see the full tree.
Do built-in features work in all browsers?
The features in this guide work in all current major browsers. Check support for your audience on a site such as Can I Use, and add a small fallback only if analytics show users on older browsers.




