---
title: "How to use NPM packages outside of Node"
description: "Many npm packages depend on Node-only globals like Buffer or built-ins like fs and net, which break on Vercel Edge Functions, Cloudflare Workers and browsers."
url: "https://swe.quest/articles/how-to-use-npm-packages-outside-of-node-508dc33f07d169fa"
canonical: "https://neon.com/blog/using-npm-packages-outside-node"
source: "Neon"
published: "2023-11-06"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["javascript","serverless","build-systems","postgres"]
---

# How to use NPM packages outside of Node

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-11-06, 6 min read, How-to. Original: [https://neon.com/blog/using-npm-packages-outside-node](https://neon.com/blog/using-npm-packages-outside-node)

## Summary

Many npm packages depend on Node-only globals like Buffer or built-ins like fs and net, which break on Vercel Edge Functions, Cloudflare Workers and browsers. Using esbuild bundling, the techniques progress from simplest to hardest: install third-party shims, inject global shims with --inject (with checks for booby-trapped Buffer and process.nextTick), add stub packages as local file: dependencies, reimplement small modules like StringDecoder and url.parse, and reimplement complex ones such as net.Socket over WebSockets. A final trick, package masquerading, substitutes a dependency (pg) with another (@neondatabase/serverless) via a same-named local package. The examples come from building Neon's serverless Postgres driver from node-postgres.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Build systems](https://swe.quest/tags/build-systems.md) (Engineering practices)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)

## Prerequisites

- npm package.json dependencies
- JavaScript module bundling ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- Node.js built-in modules ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))

## Keywords

esbuild, npm, @neondatabase/serverless, node-postgres, Cloudflare Workers, Vercel Edge Functions, WebSockets, Zapatos

## Related posts

- [Edge Functions: Node and native npm compatibility](https://swe.quest/articles/edge-functions-node-and-native-npm-compatibility-4f29863e45494db0.md): Supabase · 2023-12-12 · Medium · 3 min read · Serverless, JavaScript, Observability
  Supabase Edge Functions now natively support npm modules (via \`npm:\` imports) and Node built-in APIs, so existing Node apps using Express, node-postgres and Drizzle can migrate with minimal changes.
- [Bun v0.5](https://swe.quest/articles/bun-v0-5-b38dde54130b760c.md): Bun · 2023-01-18 · Medium · 7 min read · JavaScript, Runtimes & VMs, Build systems
  Bun v0.5 adds npm workspaces support (installing the Remix monorepo in about 500ms, claimed 28x faster than npm), a Bun.dns lookup API backed by c-ares, node:readline, and socket support via node:net and node:tls that lets database drivers like Postgres.js, mysql2 and node-redis run for the first time.
- [Bun 1.2](https://swe.quest/articles/bun-1-2-646ed14b09e00278.md): Bun · 2025-01-22 · Medium · 56 min read · JavaScript, Runtimes & VMs, Cloud platforms, PostgreSQL, Performance engineering
  Bun 1.2 makes a major push on Node.js compatibility by porting thousands of files from the Node.js test suite into Bun's CI, with stubbed internal bindings and assertions on error name/code rather than message text.
- [The Bun Bundler](https://swe.quest/articles/the-bun-bundler-1ad40102ca8fa3b8.md): Bun · 2023-05-16 · Medium · 10 min read · JavaScript, Build systems, Developer tools, Web performance
  Bun now ships a native bundler in beta, exposed as the \`bun build\` CLI and the \`Bun.build()\` JavaScript API.
- [Bun v0.6.7](https://swe.quest/articles/bun-v0-6-7-7c277e48946bb12b.md): Bun · 2023-06-02 · Medium · 4 min read · JavaScript, Runtimes & VMs
  Bun v0.6.7 fixes Node.js compatibility bugs in Node-API, node:http, undici, WebSocket, node:net and CommonJS/ESM interop, which lets Prisma, Discord.js and Puppeteer run in Bun.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
