Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

364
Views
Modules Javascript: logger.js (undefined-undefined): undefined

So. I use for this Javascript and Node.js . It's a simple program but because it's my first time working with modules and I have no idea what I am doing.

logger.js

let log= function(message){
    console.log(format(message));
}

let format = function(message){
    let dt = Date()
    let msg = 'logger.js ('+dt.getFullYear+'-'+dt.getMinute+'): '+message;
    return msg;
}

module.exports = log();
module.exports = format();

loggertest.js

let logger = require('./logger');

logger.log('Info: The new logger works perfectly!');
console.log(logger.format('Info: The new logger works perfectly!'));

The Error:

C:\programs\Node js Tasks\Logger>node loggertest
logger.js (undefined-undefined): undefined
C:\programs\Node js Tasks\Logger\loggertest.js:3
logger.log('Info: The new logger works perfectly!');
       ^

TypeError: logger.log is not a function
    at Object.<anonymous> (C:\programs\Node js Tasks\Logger\loggertest.js:3:8)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47

Would be nice if someone explains my Mistakes in detail to me. It's my first time with this all and I would like to know as much as possible, so I don't make the same mistakes again. Thanks for the help. ^^

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let log = function (message) {
    console.log(format(message));
}

let format = function (message) {
    let dt = Date()
    let msg = 'logger.js (' + dt.getFullYear + '-' + dt.getMinute + '): ' + message;
    return msg;
}

module.exports = {
    log,
    format,
}

and then

const logger = require('./logger');

logger.log....
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!