npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

remote-import

v0.0.11

Published

Import modules from a URL with a customized module loader.

Downloads

12

Readme

REMOTE-IMPORT (REMOTE-RUN)

Import remote modules from URLs. It's implemented with a customized node module loader so that it supports URL imports in transitive-dependent modules. It also provides a CLI tool remote-run to run remote js file directly.

Background

When Deno just launched, I was excited with the ability to import modules from any remote URL so that we can get rid of the cumbersome packages.json setup and bloated node-modules folders. If not because of the NPM ecosystem, I'd completely move to Deno. Unfortunately, Deno is not well integrated with the existing NPM ecosystem. I still have to stick with NPM. After a bit of research, I build this small library/CLI to bring the ability to import or run modules from a URL.

There're few existing solutions, but none of them satisfy my requirement. Most of them support the first level of remote import. They won't work if there're remote imports within the imported module. This library solved this issue by customizing Node module loader logic. It overrides Module._resolveFilename(), so that whenever a remote URL is detected, it will download the remote module and cache it locally.

Features

  • Support import with URL starts with http:// and https://
  • Support transitive imports in the dependent modules
  • Support import CommonJs modules
  • Support ES6 modules with the pre-loaded library: esm. node -r esm
  • Customizable local cache folder
  • Customizable cache refresh duration
  • Support Http head of if-match and if-modified-since for efficient file downloads and caching
  • Remote-run is a CLI tool to execute javascript from a remote URL

Usage

Install & Setup

  • npm install: npm i remote-import or install globally: npm i --global remote-import

  • In Javascript/Typescript:

    // During app initialization
    import RemoteImport from 'remote-import';
    RemoteImport.get().init({refreshDuration:10000});  // Optional, call init only if custom configuration is needed
    
    // Anywhere else
    import _ from "https://jspm.dev/lodash";
    _.add(1,2);
    
  • If the dependent modules contain ES6 modules, make sure to add the following parameter when launching the app:

    node -r esm 
  • It can also be used as pre-load module, e.g.

    node -r remote-import

    Note it doesn't work if combined with esm on REPL (Not sure why): e.g. node -r esm -r remote-import is not working if esm is needed in REPL, a pre-load esm only node -r esm and manually run require("remote-import") inside REPL.

  • Command line tools

    • Installation: npm install -g remote-import or yarn global add remote-import
    • remote-run: Directly invoke JS on remote URL:
      npm install -g remote-import
      remote-run https://raw.githubusercontent.com/treedoc/remote-import/main/sample/sample.js args
    • remote-node: Start a node REPL session with remote import support
  • For more live examples, please refer to folder sample

  • Custom configuration by calling RemoteImport.get().init(config) refer to class RemoteImportConfig

Future Enhancement

  • Add URL rules to allow list URL and indicate if the URL is immutable for security reasons.
  • Support typescript

Contributions

Even this library may provide useful functions. It's still rudimentary—lots of opportunities for enhancements. If you find any issues or have any better ideas, you are welcome to open Github issues or submit PRs.

License

Copyright 2021 TreeDoc.org Author/Developer: Jianwu Chen

Use of this source code is governed by an MIT-style license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.