In order to debug with node-inspector I need to start my app with the node --debug command. Up to this point I have only used sails lift to start my Sails.js app, so I am unsure of how to start my app using the normal node command.
- 10,215
- 9
- 69
- 120
-
possible duplicate of [How to debug a basic node.js application (not http) on windows](http://stackoverflow.com/questions/11437958/how-to-debug-a-basic-node-js-application-not-http-on-windows) – Francisco Corrales Morales Mar 29 '15 at 22:02
5 Answers
So you can actually launch a sails project with node app.js --debug if you have sails installed in your project, rather than only system-wide. Go to your project's root directory and run npm install. Sails should already be in your package.json and thus should install to your project directory.
- 10,215
- 9
- 69
- 120
-
2Note that there are more steps involved, like starting node-inspector: http://stackoverflow.com/a/11463248/168205 – dbasch Jun 03 '14 at 14:39
As of Sails v0.10.x, you can do sails debug instead of sails lift.
- 4,075
- 2
- 33
- 33
-
-
1`sails inspect` for sails 1.0 and newer node: https://stackoverflow.com/a/49676411/895245 otherwise fails with https://github.com/balderdashy/sails/issues/4593 "DeprecationWarning: node --debug and node --debug-brk are invalid." – Ciro Santilli OurBigBook.com Feb 20 '19 at 23:52
-
1Thanks @CiroSantilli郝海东冠状病六四事件法轮功, original answer failed for me. Your comment worked. – darkhipo Jan 01 '21 at 17:47
sails inspect since Sails v1.0
As of sails v1.0, sails debug is deprecated for newer Node.js, and you should instead use sails inspect.
This is documented at: https://sailsjs.com/documentation/reference/command-line-interface/sails-inspect and is presumably done to match the newer node --inspect interface.
- 347,512
- 102
- 1,199
- 985
- 51
- 6
-
Documented at: https://sailsjs.com/documentation/reference/command-line-interface/sails-inspect This is presumably to match the newer `node -inspect`. – Ciro Santilli OurBigBook.com Feb 20 '19 at 23:49
Have you tried using node-webkit to run your node.js apps? This is what we use at work to debug our node.js server applications. It is quite useful runtime based on chromium which you can use to inspect your code using familiar breakpoints, stack traces, variable inspection and such without having to rely on node-inspector (which I find hard to use to be honest).
What you do is instead of using console command 'node you-app.js' you set the node-webkit to launch your app, run the webkit then open its console (which is the same as console in Chrome browser) and from there you can open your source files and start debugging like any other client side JavaScript code.
- 5,320
- 1
- 32
- 43
node inspect
You can also use the command line debugger with:
node inspect app.js
This stops at the beginning, so do a continue:
c
And now, when your code with a statement:
debugger
gets executed, you fall into the Node CLI debugger as usual.
Tested on Sail v1.1, Node v10.15.1, Ubuntu 18.10.
nodemon --inspect and nodemon inspect
You can use those to inspect when using nodemon, which automatically reloads the app on file save: Auto reloading a Sails.js app on code changes?
Those options are analogous to node inspect and node --inspect: node inspect works with debugger statements, and node --inspect works with the Chrome debugger.
Especially useful with the "Open dedicated DevTools for Node" feature: Can I get node --inspect to open Chrome automatically
nodemon inspect is a bit annoying as it requires a continue everytime you make any app changes and nodemon restarts the server. TODO find a way around it.
- 347,512
- 102
- 1,199
- 985