# require-urls

> Deno like and GoLang like Mode in ES and commonjs: Replace nodejs require function with `requireurls` function or `use loader functionality using loader.mjs` replacing import functionality that can fetch remote urls. `require-urls` helps you require remot

Latest version **1.1.2** (published 2023-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install require-urls
pnpm add require-urls
yarn add require-urls
bun add require-urls
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2023-05-27 |
| First published | 2022-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 10 |
| Unpacked size | 340.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ganesh Bhat |
| Maintainers | ganeshkbhat |
| Keywords | require, urls, remote, requireurl, require-url, requireurls, require-urls, urlrequire, url-requires, url-require, urlrequires, deno style require, golang style require, cache remote require files |

## Links

- npm: https://www.npmjs.com/package/require-urls
- Repository: https://github.com/ganeshkbhat/requireurl
- Homepage: https://github.com/ganeshkbhat/requireurl#readme
- Issues: https://github.com/ganeshkbhat/requireurl/issues
- npm.io page: https://npm.io/package/require-urls

## Dependencies (10)

- [fssys](https://npm.io/package/fssys.md) 1.0.2
- [git-apis](https://npm.io/package/git-apis.md) 0.0.25-beta
- [svn-apis](https://npm.io/package/svn-apis.md) 0.0.12-beta
- [root-dirs](https://npm.io/package/root-dirs.md) 0.0.3
- [hasher-apis](https://npm.io/package/hasher-apis.md) 0.2.6
- [get-imported](https://npm.io/package/get-imported.md) ^0.0.7
- [request-apis](https://npm.io/package/request-apis.md) 0.0.27-beta
- [filelock.json](https://npm.io/package/filelock.json.md) 0.0.21-beta
- [concurrency.js](https://npm.io/package/concurrency.js.md) 0.0.3
- [mercurial-apis](https://npm.io/package/mercurial-apis.md) 0.0.11-beta

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2023-05-27
- 1.1.0 — 2023-04-03
- 0.0.7 — 2022-10-14
- 0.0.6 — 2022-10-06
- 0.0.5 — 2022-10-03
- 0.0.4 — 2022-10-03

## README

# require-urls

#### `Deno and GoLang Mode in commonjs import (require) and ES import syntax`

Replace nodejs require function with `requireurls` function or `use loader functionality using loader.mjs` replacing import functionality that can fetch remote urls. `require-urls` helps you require remote files (individually or recursively) from `git`, `svn`, `mercurial`, `ftp`, `remote cloud stores` using the `requireurls function. Please check the features section for currently available features.

This module has a single simple function `requireurls` for URL (git raw file) resolution and parsing meant to have feature parity with node.js core url module.

It also, by default, allows for cacheing (rather storing) files in a temporary working folder/repository. The files are stored in `.jscache` temporary folder. The file can be pulled from the cache, if already cached. You can force update the cache file if needed. The `.jscache` looks like the folder in the repository saved. You have an option to cache the files into node cache using the [require.cache](https://nodejs.org/api/modules.html#requirecache) option by specifying `cacheFetch` option. Do have a look at it.

### DEMOS

Find the demos in the [demo folder](./demos/)

### INSTALLATION

`npm install require-urls --save`

npm Package: [require-urls](https://www.npmjs.com/package/require-urls)

### USAGE

```

let requireurls = require("require-urls");
let request = "https://raw.githubusercontent.com/ganeshkbhat/requireurl/main/index.js";
let options = {};
requireurls(request, options);

```

Run the file using the following command:

```
node --experimental-loader=./node_modules/require-urls/src/loaders/loader.mjs ./file.js
```

### FEATURES

Currently, the project is in development and support the following features:

- Import `remote file` from a remote URL (Github support)
- Import `remote file and its dependencies recursively` from from a remote URL (Github support)
- Import files are `cached` in `.jscache` folder in the project
- [TODO] Minor addition of using `package.json` to import entire package installation for use
- [TODO] Support of other repositories like `svn`, `mercurial`, `ftp`, or any `other cloud` stores.


#### `options` OBJECT

```
/* You can add all inbuilt default options of require's resolve function */
```

The default require options can be found here: [require.resolve](https://nodejs.org/api/modules.html#requireresolverequest-options). All other options customized for `require-urls` function's `options` argument object are as below:

```
/* options: git, bitbucket, gitlab, svn [TODO], ftp [TODO], etc.*/
/* Default is `git`. */

baseType: "git"
```

```
/* recursive: will allow for recursive pull and cache of files relative to remote url path. */
/* Default is false. */

recursive: false
```

```
/* forceUpdate: force update the .jscache folder for the remote url files.*/
/* Default is false. */

forceUpdate: false
```

```
/* logger: provide a logger function to use.*/
/* Default is console.log */

logger: console.log
```

```
/* Adds the `.jscache` or remotely fetched files using `require.cache` feature of nodejs */
/* Default is false */

cacheFetch: true
```

```
/* getMethods: Get all the methods of require-urls.*/
/* Default is false */
/* Usage: requireurls("", { getMethods: true }) */
/* Returns an object { remoteUrl, recursiveUrl, packageJson } instead of a requireurls function */

getMethods: false
```

```
/* noRequire: Get all the methods of require-urls.*/
/* Default is false */
/* Usage: requireurls("", { noRequire: true }) */
/*  */

noRequire: false
```

#### DEMO USAGE CODE

```


let requireurls = require("require-urls");

let fileone = requireurls("https://raw.githubusercontent.com/ganeshkbhat/requireurl/main/index.js");
let filetwo = requireurls("https://raw.githubusercontent.com/ganeshkbhat/requireurl/8d8681c4a28d64f23fb473064fa86880a0b930ff/index.js");
let filethree = requireurls("https://github.com/ganeshkbhat/requireurl/blob/main/index.js");


let requireurls = require("require-urls");
let c = requireurls(
        /* request remote url */
        "https://raw.githubusercontent.com/ganeshkbhat/requireurl/8d8681c4a28d64f23fb473064fa86880a0b930ff/index.js",
        {
            /* You can add all inbuilt default options of require's resolve function */

            /* options: git, bitbucket */
            baseType: "git",
            /* recursive: will allow for recursive pull and cache of files relative to remote url path */
            recursive: true,
            /* forceUpdate: force update the .jscache folder for the remote url files */
            forceUpdate: true,
            /* logger: provide a logger function to use. default is console.log */
            logger: console.log
        });

c.then(d => console.log("testing", d));


```

```


// Importing using the CommonJS and ES import Syntax
// RUN command with --experimental-loader to run the files through the import syntax support for remote url requires or imports:
// node --experimental-loader ./node_modules/require-urls/loader.mjs ./file.mjs
// node --experimental-loader ./node_modules/require-urls/loader.mjs ./file.js

let c = import("https://github.com/cgi-js/cgi-js/blob/main/src/configs.js");
console.log("[require-urls] demo-import.mjs ", cgijs);


```

```


// Importing using the ES import Syntax
// RUN command with --experimental-loader to run the files through the import syntax support for remote url requires or imports:
// node --experimental-loader ./node_modules/require-urls/loader.mjs ./file.mjs

import  cgijs from "https://github.com/cgi-js/cgi-js/blob/main/src/index.js";
console.log("[require-urls] demo.mjs ", cgijs);

import  { default as cgijsd } from "https://github.com/cgi-js/cgi-js/blob/main/src/index.js";
console.log("[require-urls] demo.mjs ", cgijsd);


```


```

// Importing remote files and dependencies files recursively

let requireurls = require("require-urls");
let d = requireurls("https://github.com/cgi-js/cgi-js/blob/main/src/index.js", {
    baseType: "git", recursive: true, forceUpdate: true,
    logger: console.log, cacheFetch: false,
    getMethods: false, noRequire: false
    });
console.log("[require-urls] demo-recursive.js: Getting cgi-js file: ", d.then(r => console.log(r)));

```

# ERRORS DOCUMENTATION

Documented Errors [errors](./docs/errors.md)

### TODO

- [D] Github support for remote files import
  - [D] single file import.
  - [D] file import and dependency file imports recursively.
  - [D] importing project using package.json.
- [T] Gitlab support for remote files import
  - [T] single file import.
  - [T] file import and dependency file imports recursively.
  - [T] importing project using package.json.
- [T] Bitbucket support for remote files import and testing for
  - [T] single file import.
  - [T] file import and dependency file imports recursively.
  - [T] importing project using package.json.
- [P] Naming of folders based on
  - [P] `domain > user@repo > SHA`
  - [D] `domain > user@repo > commit`
  - [P] `domain > user@repo > tag`
  - [D] `domain > user@repo > branch`
- [P] Add options to import a remote published or unpublished package using `https://remoteurl/.../package.json` pack of repository.
- [P] Files imported are documented in `filelock.json` file with their content one-way cryptographic hash.
- [P] Add verify command for files in `.jscache`.
- [P] Add support for `.ts` (typescript) files import with transpiling dynamically during import.
- [P] Add support for `.coffee` (coffeescript) files import with transpiling dynamically during import.
- [T] Add support for FTP.
- [T] Add support for SVN.
- [T] Add support for Mercurial.
- [T] Consider support for S3.
- [T] Consider support for Google Cloud.
- [T] Consider support for Google Drive.

### CONTRIBUTIONS

Contributions, Feature Improvements, Bugs, and Issues are invited. [raising an issue](https://github.com/ganeshkbhat/requireurl/issues)

# LICENSE

[MIT License](./LICENSE)

---
_Source: https://npm.io/package/require-urls · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
