Coming from the background of developing web apps using server-side languages/platforms such as java, python/django and php, I am starting to learn Node.js and yeoman. I consider being able to debug server-side code essential in order to improve code quality. Node supports debugging via node-inspector and --debug option. But if an application is created out of yeoman using a generator, say AngularJS, and launched using grunt, is there an easy way to enable debugging?
Perhaps a higher level question I should first ask is: If yeoman promotes (as featured in tutorial) AngularJS, which is a client-side MVC framework, then majority of code will run from browser rather than from Node. Is that the reason why server-side debugging is not important any more to yeoman and therefore not documented?
Yeoman generators also provide a debug mode to log relevant lifecycle information. You can activate it by setting the DEBUG environment variable to the desired scope (the scope of the generator system is yeoman:generator ).
Yeoman is an open source client-side scaffolding tool for web applications. Yeoman runs as a command-line interface written for Node.
Simple like that:
npm install -g node-inspector
node-debug yo GENERATOR_NAME
It's gonna open a Chrome DevTool with an initial breakpoint.
I am developing a yemoan angular-fullstack application. I debug the server side node js application code as follows;
express: {
dev: {
options: {
script: 'server/app.js',
debug: true
}
}
}
node-inspector
.http://127.0.0.1:8080/debug?port=5858
. (If you see the grunt console, you would see the node debugger is on port 5858).debugger
statement in your code to force node to break at that point and wait for your inspection.Note: node-inspector --no-preload loads the node inspector quicker.
install node-inspector:
$ npm install -g node-inspector
start Node Inspector server:
$ node-inspector
run node.js with Yeoman-cli in debug mode:
$ node --debug path\to\global\npm\node_modules\yo\cli.js MyGenerator
where 'MyGenerator' is Yeoman generator name which you want to debug.
On Windows "path\to\global\npm" is something like "C:\Users{UserName}\AppData\Roaming\npm".
open Chrome or Opera and go to http://localhost:8080/debug?port=5858
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With