nodejs, i cant module.exports more than 1 function

if i do:

 /database 

 module.exports = mongoConnect;
 module.exports = getDb;

and than

/app.js
const mongoConnect = require('./util/database').mongoConnect;
mongoConnect();

ERROR: mongoConnect is not a function if i do console.log(mongoConnect): ill get [Function: getDb]

but if i export like this:

module.exports = {
    mongoConnect,
    getDb,
};

than in /app.js

console.log(mongoConnect): { mongoConnect: [Function: mongoConnect], getDb: [Function: getDb] }

why in the first case it doesn't work?



Read more here: https://stackoverflow.com/questions/68474040/nodejs-i-cant-module-exports-more-than-1-function

Content Attribution

This content was originally published by amine ahardane at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: