Bump
The module.exports or exports is a special object which is included in every JS file in the Node.js application by default. module is a variable that represents current module and exports is an object that will be exposed as a module. So, whatever you assign to module.exports or exports, will be exposed as a module.
var msg = require('./Messages.js');
console.log(msg);
JS export
The export
statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module so they can be used by other programs with the import
statement.
There are two types of exports:
- Named Exports (Zero or more exports per module)
- Default Exports (One per module)
let k; export default k = 12;
import m from './test';
console.log(m);
let myFunction = ...;
let myVariable = ...;
export {myFunction, myVariable};
let myClass = ...;
export myClass;
export { myFunction, myVariable } from 'childModule1.js';
export { myClass } from 'childModule2.js';
import { myFunction, myVariable, myClass } from 'parentModule.js'
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export
https://www.tutorialsteacher.com/nodejs/nodejs-module-exports
No comments:
Post a Comment