0

I've been worked on a vue project.

This vue project use the nodejs API I've created, in simple way, they are two entire differents project which are not located in the same directory and they are launched separately.

The problem is whenever I debug a route with node --inspect --debug-break event_type.controller.js for example named:

"/eventtype/create"

exports.create = (req, res) => {
  const userId = jwt.getUserId(req.headers.authorization);

  if (userId == null) {
    res.status(401).send(Response.response401());
    return;
  }
  // Validate request
  if (!req.body.label || !req.body.calendarId) {
    res.status(400).send(Response.response400());
    return;
  }

  const calendarId = req.body.calendarId; // Calendar id

  // Save to database
  EventType.create({
    label: req.body.label,
  }).then((eventType) => {
    Calendar.findByPk(calendarId).then((calendar) => {
      eventType.addCalendar(calendar); // Add a Calendar
      res.status(201).send(eventType);
    }).catch((err) => {
      res.status(500).send(Response.response500(err.message));
    });
  }).catch((err) => {
    res.status(500).send(Response.response500(err.message));
  });
};

Even if I create a breakpoint on const userId = jwt.getUserId(req.headers.authorization);

and from my vue app I trigger the api createEventType event, my break point is not passed.

Also when I press f8 after the breakpoint on my first line with the debugger, my file close automatically.

I do not use VS Code but Vim for coding but I've heard that maybe Vs Code could allow a simplified way to debug nodesjs application.

NOTE: I use the V8 node debugger.

SkydersZ
  • 133
  • 1
  • 2
  • 9

2 Answers2

0

For newer NodeJS versions (> 7.0.0) you need to use

node --inspect-brk event_type.controller.js

instead of

node --inspect --debug-break event_type.controller.js

to break on the first line of the application code. See https://nodejs.org/api/debugger.html#debugger_advanced_usage for more information.

eol
  • 23,236
  • 5
  • 46
  • 64
  • @eoi Hi, actually I've resolved this problem with a simple console.log, I've also tried the solution you gave me, but it has been the same result as before. I think that my project can be somewhat too specific and cannot be debugged normally. – SkydersZ Jul 01 '20 at 12:41
0

The solution (even if it's not really a solution) has been to add console.log to the line I wanted to debug.

SkydersZ
  • 133
  • 1
  • 2
  • 9