1.6.0 • Published 1 year ago
deno_require_test v1.6.0
deno-require-node-module
This npm library provides a bridge for Deno scripts to require Node.js modules seamlessly. It aims to make it easier for developers to integrate Node.js modules into their Deno projects without the need for rewriting or extensive configuration. By offering an easy-to-use API, deno-require-node-module
simplifies the process of leveraging the vast npm ecosystem within Deno applications.
Installation
To utilize TypeScript support with deno-require-node-module
, ts-node
must be installed in your project's node_modules
directory:
npm install ts-node
This ensures that TypeScript files can be properly executed within the Node.js context provided by the library.
Usage
import { requireNodeModule } from 'npm:deno-require-node-module';
// Import from a TypeScript module
const { start } = requireNodeModule(
import.meta.url,
'./start',
{ ts: true }
);
start(); // Call the start function from Node.js context
API Reference
requireNodeModule
Function
export function requireNodeModule<Module = any>(
importMetaUrl: string,
moduleRelativePath: string,
options?: { ts?: boolean }
): Module;
importMetaUrl
: The URL of the import meta of the calling module. This is required for resolving the module path relative to the caller.moduleRelativePath
: The relative path to the Node.js module you want to require. This allows for seamless integration with existing Node.js modules.options
: An optional parameter that adds TypeScript support usingts-node
.