Use Chrome or Safari to Debug your Node.js codes

1. Install node-inspector

npm install node-inspector

2. Start up node-inspector

node-inspector

>visit http://0.0.0.0:8080/debug?port=5858 to start debugging

3. Start up node

node –debug test.js

>debugger listening on port 5858 >Server running at http://127.0.0.1:8124/

4. Open URL: http://127.0.0.1:8080/debug?port=5858 in Chrome or Safari, Open Inspector in your browser, select the test.js file

5. Add a breakpoint in the test.js file

6. Open URL: http://127.0.0.1:8124/

You should see what you want.

test.js file:

var http = require('http');

var x = 0;
http.createServer(function (req, res) {
  x += 1;
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World ' + x);
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');

 

Comments are closed.