Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/std/node/module.ts>default.createRequire

A modern runtime for JavaScript and TypeScript.
Go to Latest
method default.createRequire
import { default } from "https://deno.land/x/deno@v0.28.0/std/node/module.ts";

Create a require function that can be used to import CJS modules. Follows CommonJS resolution similar to that of Node.js, with node_modules lookup and index.js lookup support. Also injects available Node.js builtin module polyfills.

const require_ = createRequire(import.meta.url);
const fs = require_("fs");
const leftPad = require_("left-pad");
const cjsModule = require_("./cjs_mod");

Parameters

filename: string | URL

path or URL to current module

Returns

RequireFunction

Require function to import CJS modules