Skip to content

Node.js set console log location

By default, no console log location is defined for Node.js applications. You can set one using the LSNODE_CONSOLE_LOG environment variable.

  1. Navigate to your Node.js application list in cPanel and click Edit on the desired application.
  2. Under the environment variables section, add:
    • Name: LSNODE_CONSOLE_LOG
    • Value: /home/username/pathtoapp/console.log
  3. Save the application. All console.log() output will now be written to this file.

For more advanced setups, you can define the environment variable in the .htaccess file of your application’s document root:

<IfModule Litespeed>
SetEnv LSNODE_CONSOLE_LOG /home/username/nodeapp/console.log
</IfModule>

To test, add the following to your application code:

console.log('Testing logging');