Home / Companies / Neon / Blog / Post Details
Content Deep Dive

How to use NPM packages outside of Node

Blog post from Neon

Post Details
Company
Date Published
Author
George MacKerron
Word Count
1,600
Language
English
Hacker News Points
-
Summary

George MacKerron illustrates techniques to run NPM packages outside of Node.js environments, such as Vercel Edge Functions and web browsers, using esbuild to create runnable bundles. He highlights the challenges posed by Node-specific features in NPM packages, which can hinder their use on non-Node platforms. MacKerron shares strategies like using third-party shim libraries for global objects, creating stub packages for less critical Node libraries, and re-implementing Node features for essential functionalities. He also discusses package masquerading to substitute dependencies, demonstrating these methods in the development of the @neondatabase/serverless driver, adapted from the node-postgres pg package, to make Postgres usable on serverless platforms.