Is it possible to export the whole Node.JS
module and have the following features:
- Import this module from another module
- Get all
methods
andattributes
set into this module - I do not want to wrap any part of this code from my module into a function/class?
For example, I want to create a REST.js
module which has the following attributes and methods:
let a = 10
let b = 20
const funcA = (x) => {
//functionA code
}
const funcB = (x, y) => {
//functionB code
}
This module needs to be imported into app.js
using some syntax which enables me to use the following API (or similar) to get attributes and use methods from REST.js
:
const REST = require('REST')
//get attributes
console.log(REST.a)
console.log(REST.b)
//use methods
let resA = REST.funcA(10)
let resB = REST.funcB(10, 20)
All in all, I want to know if there is a similar to Python
syntax for using modules.
Yes, but in
NodeJS
, you must explicitly export thevariables/functions
like this: