Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use node-inspector with sails.js?

I would like to debug my sails.js application but I don't know how to launch node-inspector for this occasion.

Normally it would go :

$ node --debug myapp.js

If I run my sails application normally :

$ sails lift --prod

and then launch node-inspector

$ node-inspector --debug-port 1337
Node Inspector v0.7.0-2
   info  - socket.io started
Visit http://127.0.0.1:8080/debug?port=1337 to start debugging.

I get this error in inspector GUI :

Error: read ECONNRESET. Check there is no other debugger client attached to port 1337.
like image 553
Patryk Avatar asked Jan 26 '14 14:01

Patryk


People also ask

How do I start node inspect?

After installing run it using node-inspector command as shown below. As you can see in the above figure, it will display an URL for debugging purpose. So, point your browser to http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 and start debugging. Sometimes, port 8080 might not be available on your computer.

How do I debug sails app?

Attach the Node debugger and lift the Sails app (similar to running node --inspect app. js ). You can then use a tool like Chrome DevTools to interactively debug your apps (see the Node Inspector docs for more information).

Is sails js a good framework?

A big reason why sails. js is hailed by developers is because of how suitable it is for building real-time features, like for example, a live chat option. It is also very compatible with Angular and Backbone. In short, it is the perfect framework for customised enterprise applications which are heavy on data.

What is inspector in node js?

Node Inspector is a debugger interface for Node. js applications that uses the Blink Developer Tools (formerly WebKit Web Inspector). Since version 6.3, Node. js provides a built-in DevTools-based debugger which mostly deprecates Node Inspector, see e.g. this blog post to get started.


2 Answers

As of Sails 0.9.8 you can use sailsd to call sails in debug mode, e.g. sailsd lift.

-- Edit --

Looks like this didn't actually make it into 0.9.8, my bad. To make your own debugging command for now, save the following into /usr/local/bin as sailsd (or whatever you like):

#!/bin/sh
node --debug `which sails` $@

-- Edit 2 --

In Sails v0.10.x, you can do sails debug instead of sails lift to start Sails in debug mode!

like image 186
sgress454 Avatar answered Nov 15 '22 21:11

sgress454


Correct me if im wrong but, you cant use debug port 1337 if sails lifts on port 1337.

try specifying a different port.

node --debug app.js
#this will lift sails on port 1337 and the default debug port i think its 5858
#start node-inspector, once it starts hit enter to put it into background
node-inspector &;
#visit http://127.0.0.1:8080/debug?port=5858

edit just confirmed this method works, instead of using sails lift you're using node to start app.js in debug mode. the node-inspector web runs on port 8080 and the debugger links on port 5858 by default.

like image 32
NDBoost Avatar answered Nov 15 '22 23:11

NDBoost