Middle+
What are the features of CommandJS?
sobes.tech AI
Answer from AI
- Uses synchronous module loading.
- Suitable for server-side development (Node.js).
- Each file is considered a module.
- Export is done using
module.exportsorexports. - Import is performed using
require().
Example of export:
// commonjs-module.js
const myVariable = 'Hello, CommonJS!';
module.exports = {
myVariable
};
Example of import:
// app.js
const myModule = require('./commonjs-module');
console.log(myModule.myVariable); // Outputs: Hello, CommonJS!