Reputation: 26084
When using the ES6 import
command, you can use an alias to import all functions from a file, for example:
import * as name from "module-name";
Is there an equivalent way to do this using require, i.e.:
const { * as name } = require('module-name');
Upvotes: 7
Views: 3658
Reputation: 516
As simple as:
const name = require('module-name')
Usage:
name.yourObjectName
Upvotes: -1
Reputation: 26084
const name = require('moduleName.js');
This means that when you have (moduleName.js)...
function foo(){
...
}
module.exports = { foo };
...the foo()
function can be accessed by another file using:
const name = require('moduleName.js');
name.foo();
Upvotes: -2