Skip to content

Instantly share code, notes, and snippets.

@SMotaal
Last active February 27, 2019 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SMotaal/e73c12bd801d78a3108fa30ecd303676 to your computer and use it in GitHub Desktop.
Save SMotaal/e73c12bd801d78a3108fa30ecd303676 to your computer and use it in GitHub Desktop.
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