Michael Michael - 8 months ago 42
Node.js Question

node.js - console.log does not work in public/javascript/ file

console.log does not work for me when I place it in a function in public/javascripts folder.

My current node.js folder structure is:

  • views

  • routes

  • public

    • javascripts > utils.js

In utils.js, i have this function

function goToGoogle () {
alert ('Hello World');
console.log('Hello World');

The alert() command works fine, but not the console.log

I've tried the console.log in other js files in the routes/ directory and it outputs to the terminal just fine.

Any idea? Thanks


If the code is in public then I assume it runs in the browser. That means messages will come up in the browser's console, not Node's console. In Chrome for instance you go to Tools -> Javascript Console in the menu.

The reason it works in other files is because the JS for routes runs in Node and thus uses Node's console.