Modules: Feature: Arbitrary sources for module source text

Created on 19 May 2018  路  4Comments  路  Source: nodejs/modules

  • I want to load modules from a database and not from the filesystem.
  • I want to load modules from a URL.

Use case 6. Related to use case 38, about --eval for ESM code.

features

Most helpful comment

I would expect that there'd be a way to do both of the following:

  1. programmatically create a module, perhaps with VM.module, from an arbitrary string, and define it to be importable at some path
  2. define a custom loader that can handle custom URL protocols, or custom paths, that can load source text in real time.

All 4 comments

This can be partially solved by the vm.Module constructor and linking and evaluating the module yourself. Obviously it's not that elegant so I wouldn't call it a done solution, but at the very least the use case is accomplishable.

Perhaps the --loader flag thing would also enable this use case, but I'm not too familiar with it.

Sorry I don't understand this use case, could you please provide a few examples?

Are the following example in this use case?

import tty from "unix:///dev/tty0"
import file from "file://tmp/foo"
import something from "tcp://localhost"

Pinging @ceejbot as this was their use case.

I would expect that there'd be a way to do both of the following:

  1. programmatically create a module, perhaps with VM.module, from an arbitrary string, and define it to be importable at some path
  2. define a custom loader that can handle custom URL protocols, or custom paths, that can load source text in real time.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mhdawson picture mhdawson  路  4Comments

guybedford picture guybedford  路  3Comments

SMotaal picture SMotaal  路  5Comments

GeoffreyBooth picture GeoffreyBooth  路  5Comments

vejja picture vejja  路  5Comments