About 29,200 results
Open links in new tab
  1. ES6 import equivalent of require() without exports

    Sep 3, 2017 · By using require(./filename) I can include and execute the code inside filename without any export defined inside filename itself. What is the equivalent in ES6 using import? Thanks

  2. node.js - Using require without export - Stack Overflow

    To get it to work, I need to export the foo object from my module, using the module.exports that you are familiar with. This demonstrates that you don't need to export anything from your modules, just like you don't need to bind the imported module to …

  3. Using Node.js require vs. ES6 import/export - Stack Overflow

    Jul 11, 2015 · node --experimental-modules index.mjs lets you use import without Babel and works in Node 8.5.0+. You can (and should) also publish your npm packages as native ESModule, with backwards compatibility for the old require way.

  4. Import and Export in Node.js - GeeksforGeeks

    Jan 7, 2025 · Node.js also allows importing and exporting functions and modules. Functions in one module can be imported and called in other modules saving the effort to copy function definitions into the other files. The module can be edited or debugged separately making it easier to add or remove features. Steps to include functions from other files.

  5. Usingimport” instead of “require” in Node.js - Medium

    Apr 25, 2024 · In this article, let’s see how to transition from “require” to “import” in a Node.js project. ECMAScript Modules (ESM) is a standardized module system in JavaScript that allows you to use...

  6. How To Use An ES6 Import In Node.js? - GeeksforGeeks

    Jan 7, 2025 · To use an ES6 import in Node.js, you need to make some configurations to support ES6 modules. While Node.js was originally built around the CommonJS module system (require () and module.exports), modern JavaScript development prefers using the ES6 module syntax (import and export).

  7. Use Import Instead of Require in Node App - Plain English

    Jul 12, 2021 · Thanks to the support of ESM files in Node.js, the days of using const something = require('something') are a thing of the past. Let’s learn how easy it can be to switch to using **import statements **in your new Node,js projects.

  8. How to use `import/export` in Node without Babel - Corey Cleary

    There is experimental support for ECMAScript modules in newer version of Node using the --experimental-modules flag. But I've found a more robust and interoperable solution to use is the esm module. First, install the module with npm i esm or yarn add esm (if you're using Yarn).

  9. Using import/export in node.js with esm | by Jamis Charles

    Jul 8, 2018 · Thankfully John-David Dalton (who created Lodash) made the esm module, which allows us to use es6 import/export syntax in node without a build step. Esm is a simple npm module. First we’ll...

  10. Difference Between Node Require and ES6 Import And Export

    Feb 18, 2025 · NodeJS offers two ways to do this: CommonJS (require ()) and ES6 modules (import/export). Both achieve the same goal—sharing code, but use different syntax. CommonJS is the older, traditional way. ES6 modules are newer and offer some advantages, but both are commonly used in NodeJS development.

Refresh