This Tech Bite was brought to you by Kenan Klisura, Lead Software Engineer at Atlantbh.
Tech Bites are tips, tricks, snippets or explanations about various programming technologies and paradigms, which can help engineers with their everyday job.
module.exports
module.exports is an empty object and a property on the module object. odule is a special object in NodeJS which contains information about the current module. The exports property is used to expose properties or functions of the current module. Use require to import properties from some module.
// file.js module.exports = “Hello world”;
|
// file2.js module.exports = { fn: function () { // ... } }; |
// app.js var message = require(‘./file’); console.log(message); // Hello world var file2 = require(‘./file2’); console.log(file2.fn()); // call fn on the file2 |
With the introduction of ES Modules via ES6, an export and import keyword can be used for exporting and importing properties.
// file.js const message = “Hello world”; export default message; |
// file2.js export function fn() { // ... } |
// app.js import message from ‘./file’; console.log(message); // Hello world import { fn } from ‘./file2’; console.log(fn()); // call fn on the file2 |
February 3, 2021
Elasticsearch – Bucket Selector Aggregation
This Tech Bite was brought to you by Kristina Kraljević, Junior Software Engineer at Atlantbh. (more…)
November 11, 2020
JAVA Generics
This Tech Bite was brought to you by Nizam Alešević, Junior Software Engineer at Atlantbh. (more…)
April 27, 2020
Deploying applications using Kubernetes
This Tech Bite was brought to you by Dario Pejčinović, Junior Software Engineer at Atlantbh. (more…)