Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restify debugging in WebStorm

I'm trying to set up a very basic restify server so I can debug it in WebStorm. I can run the process normally, but when using the debug function in WebStorm the process exits immediately.

My restify server is located in the server.js folder:

var restify = require('restify');

function respond(req, res, next) {
    res.send('hello ' + req.params.name);
    next();
}

var server = restify.createServer();
server.get('/hello/:name', respond);
server.head('/hello/:name', respond);

server.listen(8080, function() {
    console.log('%s listening at %s', server.name, server.url);
});

I would like to hit a breakpoint set inside the respond function.

When I run the solution it starts up normally and I can hit the hello endpoint:

"C:\Program Files (x86)\JetBrains\WebStorm 2016.1.1\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" server.js
restify listening at http://[::]:8080

However, hitting debug I get :

"C:\Program Files (x86)\JetBrains\WebStorm 2016.1.1\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=60036 server.js
Debugger listening on port 60036

Process finished with exit code -1073741819 (0xC0000005)

My local config file looks like this (nothing special):

enter image description here

What am I doing wrong?

EDIT:

I looked at the template which WebStorm generates with express to try and find some inspiration to get debugging to work with restify. Basically I am mimicing the WebStorm template now, so I have an additional file in bin/wwww:

/**
 * Module dependencies.
 */

var app = require('../app');
var debug = require('debug')('test2:server');
var http = require('http');

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3000');
//app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
 * Normalize a port into a number, string, or false.
 */

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}

/**
 * Event listener for HTTP server "error" event.
 */

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
      ? 'Pipe ' + port
      : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

/**
 * Event listener for HTTP server "listening" event.
 */

function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
      ? 'pipe ' + addr
      : 'port ' + addr.port;
  debug('Listening on ' + bind);
}

Instead of the server file, I use app.js:

var restify = require('restify');

var restifyApp = function () {
    var server = restify.createServer({
        name: 'myapp',
        version: '1.0.0'
    });
    server.use(restify.acceptParser(server.acceptable));
    server.use(restify.queryParser());
    server.use(restify.bodyParser());

    server.get('/echo/:name', function (req, res, next) {
        res.send(req.params);
        return next();
    });
};

module.exports = restifyApp;

With this setup I am actually able to start in debug mode. However, as soon as I try http://localhost:3000/echo/hey (as an example), the request times out and once again I get feedback in the terminal with the message Process finished with exit code -1073741819 (0xC0000005)

like image 950
Ebbs Avatar asked Feb 24 '26 09:02

Ebbs


1 Answers

Looks like Node V8 issue (as debugging also fails when using node-inspector). I was able to debug your code after downgrading to Node.js 0.10.31. Node 4.3 breaks with AccessViolation, Node 5.5 hangs.

like image 68
lena Avatar answered Feb 27 '26 01:02

lena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!