0

I try to log a foreach callback to a file inside my node app. I try to use:

    var logger = fs.createWriteStream('tests/temp.js', {
        flags: 'a' 
    })

    req.body.selection.forEach(myFunction(logger));

    logger.end() // close string

In the callback I try:

function myFunction(mylogger,postvalue) {
    Object.entries(myJsonData.testCases).forEach(([key, value]) => {
        if(postvalue == key){
            console.log("gefunden");
            mylogger.write('some data') // append string to your file
        }
    });
}

But this is wrong. Anyone can help me t find the brainbreak?

1 Answer 1

2

I suggest passing an arrow function expression which propagates both the logger and the callback argument to the destination:

req.body.selection.forEach((value) => myFunction(logger, value));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.