Categories
JavaScript Answers

How to require from URL in Node.js?

Spread the love

To require from URL in Node.js, we use the require-from-url package.

To install it, we run

npm install require-from-url

Then we use it by writing

const requireFromUrl = require("require-from-url/sync");
const module = requireFromUrl("http://example.com/nodejsmodules/myModule.js");

to call requireFromUrl with the URL of the module to return the module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *