All lines of codes has different distinct standards of writing them and Javascript is of no different, hence come the ConnonJs standard which was the older way of structuring js modules.
The coomonJs comes with a method of sharing data using the export and require keywords in a different syntax;
const userDATA = () => {
return "user info"
}
module.exports = {
userDATA
}
This lines of codes showing that you want to export the data containing the userDATA while,
const {userDATA} = require ("./index.js")
console.log (userDATA())
is the syntax to import the data to another module.
commonJs is commonly used while using the Node.js for building your server side applications {API}.
Checkout my next post on the newest standard of defining your modules.
Top comments (0)