Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to use require() and import in the same time

//You can use ES6 import/export in Node.js by simply adding “type”: “module” to your package.json file, like this:
{
  "type": "module"
}

//To use “require” in ES module scope, you have to define it. Just two lines of code:
// These lines make "require" available
import { createRequire } from "module";
const require = createRequire(import.meta.url);
Source by www.kindacode.com #
 
PREVIOUS NEXT
Tagged: #import #time
ADD COMMENT
Topic
Name
3+8 =