InterviewSolution
| 1. |
How to enable debugging in express apps? |
|
Answer» By default, debugging is turned off in Express.js. As Express.js and in turn Node.js are not meant for the browser, so we cannot see the logs in the browser console. To turn on logging, we have to use a bit of a different command depending on the operating system, when we are launching the application. On a UNIX operating system, we use the below command. $ DEBUG=express:* node index.jsBut on a Windows operating system, we use a different command: > set DEBUG=express:* & node index.jsWe will create a small Express app and enable debugging to check it out. First we need to create a new folder and CHANGE directory. After that we shall use the npm init command with -y option, to create a package.json file, which is a must for any Node.js app. Notice that we have given the -y option, else we would have to answer a lot of questions. Next, we will install express in our app by the below npm command, as it comes as an external package. Now, create a file index.js and add the below code in it. This simple code will send the message HELLO WORLD, when someone goes to the home route from a browser. Now, instead of RUNNING the node command by node index.js , we will run by the command which we have learned earlier. Now, our advanced debugging is enabled in an Express App. |
|