Reputation: 69
I am new to node js and pm2. I use pm2 to run the application in background. How can view all the api hits(200,400) and stuff that is seen on console when running the app in local. I have tried pm2 logs and other commands but they don't show any api hits and stuff. Pls help me in that.
Upvotes: 0
Views: 3524
Reputation: 178
PM2 will display whatever is console logged by nodejs. There is a specific library which will do this automatically for you and is called "morgan".
https://github.com/expressjs/morgan
You just need to install it with npm from terminal:
sudo npm install --save morgan
in your server file:
var morgan = require('morgan');
app.use(morgan('dev'));
and then in terminal:
sudo pm2 restart server;
sudo pm2 logs;
should do the trick.
Sorry if there are any mistakes in my mini tutorial but I have provided you with the "morgan" module documentation so you should manage to fix any mistakes.
Upvotes: 4