文章出处:http://blog.zakkum.com/?p=63
注意:刚开始用webstorm debug nodejs的时候,总会出现一个端口一会儿能用,一会不能用的情况。
其实你的debug设置可能没有问题,出问题的是你已经监听的端口没有断开!
I would like to show you how to debug your nodejs web server applications. I’m using JetBrains’ WebStorm for some time and it’s my favourite web development tool for linux box. It’s 2.1 version. There is a nodejs plugin for debug operation in WebStorm. You can search and install plugin from File->Settings->Plugins window.
I assume that you have installed nodejs and express already. You can grab nodejs from https://github.com/joyent/node and follow installation instructions. It’s quite easy. Then you can install express with
npm install -d express
There is a “Hello world” application to test our server. Create a new javascript file and name it “app.js”
var app = require('express').createServer();
app.get('/', function(req, res){
res.send('Hello world');
});
app.listen(3000);
console.log('Server started on port 3000');
Click Run->Debug… or press alt+shift+f9 to open debug configuration screen. Click plus icon and then click nodejs option.
Give a name to your configuration. Enter your node path (get node path from terminal: which node) and type your app.js file path.
Now we are all set for debugging. Hit the debug button or press shift+f9 and you will see “debugger listenin on port …” message in console. You can make breakpoints to debug your application.