0

I'm starting on a project using Node.js, and I'm running into some issues with it's logging. I'm completely new to Node.js, but my understanding is that using console.log([data]) should print out the value of [data] to the server console.

I see this occurring how I expect in several places in this project, but when I try to add additional logging, nothing is prompted out to the console window. I've noticed that all of the files where logging is working are under a specific folder, while the bulk of the code is under another.

Does anybody know what might be the cause of these not to print out into the console? I've also tried console.error([data]) and console.warning([data]) to see if it might be due to an error but that also didn't work.

3
  • The only reasons I know of that console.log(data) would not output anything are if that code is never actually being called (perhaps because of an exception beforehand). Commented Sep 13, 2015 at 19:00
  • That was what I thought initially, but if I put an alert immediately after the logging which displays as expected. Commented Sep 13, 2015 at 19:02
  • 1
    Then show us the specific code and the context around it that is not showing anything in the console. Questions about code should nearly ALWAYS include the actual code you're asking about. I'm also wondering how you put an alert into a node.js block of code. Something sounds suspicious there. alert is a browser thing, not a node.js thing. Commented Sep 13, 2015 at 19:04

1 Answer 1

1

Without having your actual code, this is just a guess:

The files where the logging is working are the Javascript files for the server. The "bulk" of the code may be the client code (I guess so because you're saying in the comments of your post that you inserted a working alert, which is a browser thing), so your logs go to the browser not to the server.

Sign up to request clarification or add additional context in comments.

1 Comment

I think you're right. It looks like it has something to do with the middleware. The application is using Express - app.use(express.static(global.app_root_dir + "/public")); All of the files in the /public directory seem to be ran on the client side, I looked at the brower's console and see the output.

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.