Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: module.exports is not a function

My goal is to use the logger.js inside my app.js I typed this from a tutorial but I have got different results than the tutorial.

-node-tutorial --logger.js --app.js

When I type node app.js in the console, I get this:

timbliefert@Tims-Air node-tutorial % node app.js
/Users/timbliefert/Developer/node-tutorial/logger.js:9
module.exports(log) = log;
       ^

TypeError: module.exports is not a function
    at Object.<anonymous> (/Users/timbliefert/Developer/node-tutorial/logger.js:9:8)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/timbliefert/Developer/node-tutorial/app.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)```
like image 416
oase Avatar asked Sep 02 '26 12:09

oase


1 Answers

module.exports is an object by default and you haven't reassigned it to a function so you're not able to invoke it with parenthesis like a function. You can add properties to module.exports exactly like how you'd add them to an object in JS through assignment.

module.exports.log = log;
like image 57
Abir Taheer Avatar answered Sep 05 '26 02:09

Abir Taheer