Skip to main content

Essential npm Packages Every JavaScript Developer Should Know

Created: May 5, 2018 5 min read

Introduction

The npm ecosystem has over 2 million packages, which makes finding the right tools overwhelming. This guide covers the most useful npm packages across categories — from development utilities to production-ready libraries — that consistently save time and solve real problems. See Javascript Guide for more context. See Javascript Guide for more context.

Development & Prototyping

json-server

Turn any JSON file into a full REST API instantly — no backend code needed. Perfect for frontend prototyping.

npm install -g json-server
// db.json
{
  "users": [
    { "id": 1, "name": "Alice", "email": "[email protected]" },
    { "id": 2, "name": "Bob",   "email": "[email protected]" }
  ],
  "posts": [
    { "id": 1, "title": "Hello World", "userId": 1 }
  ]
}
json-server --watch db.json --port 3001

You instantly get:

  • GET /users — list all users
  • GET /users/1 — get user by id
  • POST /users — create user
  • PUT /users/1 — update user
  • DELETE /users/1 — delete user
  • Filtering: GET /users?name=Alice
  • Pagination: GET /posts?_page=1&_limit=10

live-server

A development HTTP server with live reload. Similar to python -m http.server but with automatic browser refresh on file changes.

npm install -g live-server
live-server ./public

nodemon

Automatically restarts your Node.js app when files change:

npm install -g nodemon
nodemon server.js

concurrently

Run multiple npm scripts in parallel — useful for running frontend and backend together:

npm install --save-dev concurrently
// package.json
{
  "scripts": {
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "server": "nodemon server.js",
    "client": "vite"
  }
}

HTTP & API

axios

Promise-based HTTP client with a cleaner API than fetch, automatic JSON parsing, and interceptors:

npm install axios
import axios from 'axios'

// GET request
const { data } = await axios.get('https://api.example.com/users')

// POST with JSON body
const response = await axios.post('/api/users', {
  name: 'Alice',
  email: '[email protected]'
})

// Request interceptor (e.g., add auth token)
axios.interceptors.request.use(config => {
  config.headers.Authorization = `Bearer ${getToken()}`
  return config
})

// Response interceptor (e.g., handle 401)
axios.interceptors.response.use(
  response => response,
  error => {
    if (error.response?.status === 401) redirectToLogin()
    return Promise.reject(error)
  }
)

got

A modern, lightweight HTTP client for Node.js with streams, retries, and TypeScript support:

npm install got
import got from 'got'

const data = await got('https://api.example.com/data').json()

// With retry and timeout
const response = await got('https://api.example.com/data', {
  retry: { limit: 3 },
  timeout: { request: 5000 }
}).json()

Utilities

lodash

A comprehensive utility library for arrays, objects, strings, and functions:

npm install lodash
import _ from 'lodash'

// Deep clone
const copy = _.cloneDeep(complexObject)

// Group array by property
const grouped = _.groupBy(users, 'department')

// Debounce a function
const debouncedSearch = _.debounce(search, 300)

// Pick specific keys from object
const subset = _.pick(user, ['id', 'name', 'email'])

// Flatten nested arrays
const flat = _.flattenDeep([1, [2, [3, [4]]]])  // => [1, 2, 3, 4]

// Chunk array into groups
const chunks = _.chunk([1,2,3,4,5,6], 2)  // => [[1,2],[3,4],[5,6]]

date-fns

Modern date utility library — modular, immutable, and tree-shakeable (unlike moment.js):

npm install date-fns
import { format, addDays, differenceInDays, parseISO } from 'date-fns'

format(new Date(), 'yyyy-MM-dd')           // => "2026-03-29"
addDays(new Date(), 7)                     // 7 days from now
differenceInDays(new Date('2026-12-31'), new Date())  // days until year end
parseISO('2026-03-29T10:00:00Z')           // parse ISO string

uuid

Generate RFC-compliant UUIDs:

npm install uuid
import { v4 as uuidv4 } from 'uuid'

const id = uuidv4()  // => "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"

Validation

zod

TypeScript-first schema validation with excellent type inference:

npm install zod
import { z } from 'zod'

const UserSchema = z.object({
  name:  z.string().min(1).max(100),
  email: z.string().email(),
  age:   z.number().int().min(0).max(150).optional()
})

// Validate and parse
const user = UserSchema.parse({ name: 'Alice', email: '[email protected]' })

// Safe parse (no throw)
const result = UserSchema.safeParse(unknownData)
if (result.success) {
  console.log(result.data)
} else {
  console.log(result.error.issues)
}

// Infer TypeScript type
type User = z.infer<typeof UserSchema>

joi

Powerful schema validation for Node.js:

npm install joi
import Joi from 'joi'

const schema = Joi.object({
  username: Joi.string().alphanum().min(3).max(30).required(),
  password: Joi.string().pattern(/^[a-zA-Z0-9]{8,30}$/).required(),
  email:    Joi.string().email().required()
})

const { error, value } = schema.validate(req.body)
if (error) return res.status(400).json({ error: error.details[0].message })

CLI Tools

chalk

Terminal string styling — colors, bold, underline:

npm install chalk
import chalk from 'chalk'

console.log(chalk.green('✓ Success'))
console.log(chalk.red('✗ Error'))
console.log(chalk.yellow('⚠ Warning'))
console.log(chalk.blue.bold('Info'))
console.log(chalk.bgRed.white(' CRITICAL '))

ora

Elegant terminal spinners for long-running tasks:

npm install ora
import ora from 'ora'

const spinner = ora('Fetching data...').start()

try {
  await fetchData()
  spinner.succeed('Data fetched successfully')
} catch (err) {
  spinner.fail('Failed to fetch data')
}

commander

Build CLI applications with argument parsing:

npm install commander
import { Command } from 'commander'

const program = new Command()

program
  .name('mytool')
  .description('A useful CLI tool')
  .version('1.0.0')

program
  .command('deploy <environment>')
  .description('Deploy to an environment')
  .option('-f, --force', 'Force deployment')
  .option('--dry-run', 'Simulate without deploying')
  .action((env, options) => {
    console.log(`Deploying to ${env}`, options)
  })

program.parse()

Testing

vitest

Fast unit testing framework compatible with Jest API, built for Vite projects:

npm install --save-dev vitest
import { describe, it, expect } from 'vitest'
import { add } from './math'

describe('add', () => {
  it('adds two numbers', () => {
    expect(add(2, 3)).toBe(5)
  })

  it('handles negative numbers', () => {
    expect(add(-1, 1)).toBe(0)
  })
})

msw (Mock Service Worker)

Mock HTTP requests in tests and the browser without changing your code:

npm install --save-dev msw
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'

const server = setupServer(
  http.get('/api/users', () => {
    return HttpResponse.json([{ id: 1, name: 'Alice' }])
  })
)

beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

Quick Reference

Package Category Purpose
json-server Dev Mock REST API from JSON
live-server Dev Dev server with live reload
nodemon Dev Auto-restart Node on changes
concurrently Dev Run multiple scripts in parallel
axios HTTP HTTP client with interceptors
got HTTP Modern HTTP client for Node
lodash Utility Array/object/string utilities
date-fns Utility Date manipulation
uuid Utility UUID generation
zod Validation TypeScript-first schema validation
chalk CLI Terminal colors
ora CLI Terminal spinners
commander CLI CLI argument parsing
vitest Testing Fast unit testing
msw Testing HTTP request mocking

Resources

Comments

Share this article

Scan to read on mobile