Meteor Node Stubs

1.2.27 · active · verified Sun Apr 19

meteor-node-stubs provides browser-compatible stub implementations for Node.js built-in modules (e.g., `path`, `buffer`, `process`, `crypto`). It enables NPM packages, even those initially for Node.js, to run within Meteor client-side applications by transparently redirecting imports to these browser-friendly stubs, requiring no manual configuration. The current stable version is 1.2.27, with releases tied to the broader Meteor ecosystem's update cycle for security and compatibility, including Meteor 3.x. Its key differentiator is automatic integration with Meteor's build process, minimizing client bundle bloat by only including necessary stubs.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates using Node.js built-in modules like `path` and `process` in client-side Meteor code, relying on `meteor-node-stubs` to provide browser-compatible implementations.

import { Meteor } from 'meteor/meteor';
import { basename, extname } from 'path'; // Importing Node.js 'path' module

if (Meteor.isClient) {
  Meteor.startup(() => {
    // This code runs only on the client (browser)
    const filePath = '/home/user/document.txt';
    const baseName = basename(filePath);
    const extension = extname(filePath);

    console.log(`Original Path: ${filePath}`);
    console.log(`Base Name: ${baseName}`);
    console.log(`File Extension: ${extension}`);

    // Demonstrate another common stub, 'process'
    // process.env is stubbed for browser compatibility
    console.log(`Environment (from stubbed process): ${process.env.NODE_ENV ?? 'development'}`);
    console.log(`Is browser? (from stubbed process): ${process.browser ?? true}`);

    // Example of a function that might not be fully stubbed or is a no-op
    try {
      // The 'fs' module is typically not fully implemented in browser stubs.
      // Attempting to use server-side filesystem operations will fail.
      // import * as fs from 'fs'; // If actually imported, would be at top
      // fs.readFile('/some/file.txt', () => {}); 
      console.log("Attempted to use fs (may not work as expected in browser stubs).");
    } catch (e) {
      console.warn("fs module is likely not fully implemented in browser stubs:", e.message);
    }
  });
}

view raw JSON →