The solution to debug not showing any logs in typescript is due to the reason that debug relies on the environment variables to decide how to show the logs
Solution
Make sure you have installed dotenv and its type definition file
npm install dotenv && npm install -D @types/dotenv
Then create a .env file at the root folder of your project add and this environment variable:
DEBUG = *
finally at the index file of your application. Configure dotenv to load the environment variables before any other task is run.
Its very important dotenv configuration is done at the top of the index file, before any other lines of code.
Add this two lines of code
import dotenv from "dotenv";
dotenv.config();
This should load the DEBUG environment variable required by debug to show output on the standard input.
Remember if you want to view logs defined in your files only and not other logs from other modules. Its better you define your application name as the namespace. That way you can filter the logs by the environment variable described above i.e.
const debug = debug("applicationName:other-more-information");
Then to view your debug logs alone just change the DEBUG varibale from *
to applicationName:*
DEBUG = applicationName:*
For unix based os users you can try exporting this variable to enviroment variables directly (Though i have not tested this solution) export DEBUG=*
- This method will only work for all process started on this shell