Skip to content

Instantly share code, notes, and snippets.

@SMotaal SMotaal/cjs.js
Last active Feb 27, 2019

What would you like to do?
Node.js: createRequireFromPath
module.exports = 'cjs';
import {createRequireFromPath} from 'module';
import {fileURLToPath} from 'url';
const require = createRequireFromPath(fileURLToPath(import.meta.url));
const cjs = require('./cjs');
cjs === 'cjs'; // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.