Reputation: 109
I am new to node.js and I am trying to find a way to get request object printed on browser's console instead of terminal, I use chrome.
var app = express();
app.post("/campgrounds", function(request, response) {
console.log(req);
res.send("POST");
});
How can I print request in browser's console?
The reason is that output on browser is more user-friendly and hence easier to inspect.
Upvotes: 1
Views: 1524
Reputation: 111434
You cannot directly print anything on the browser.
What you can do is either:
Send what you want printed in the response to the request and add some client-side code that would print it for all responses. You will only be able to print something once per request.
Use WebSocket or Socket.io to create a connection used only for the message printing. You need both server-side and client-side code for that but it would not be very complex. You will be able to print anything any time.
If you want 2 then see my project on GitHub that changes the website color and change the color changing code to console.log()
to print whatever was received on the socket. Of course you will need to make sure that you only print it on the browser that made the request if that is your intention.
The project that you can start from:
Upvotes: 1