Meteor: server side debugging

Does anyone know a good method for debugging server side code? I tried turning on Node.js debug and then using node-inspector, but it does not display my code.

I end up using console.log, but it is very inefficient.

Update: I found that the following procedure works on my Linux machine:

  • When you start Meteor, it will spawn two processes

    process1: /usr/lib/meteor/bin/node/usr/lib/meteor/app/meteor/meteor.js

    process2: /usr/lib/meteor/bin/node/home/paul/codes/bbtest_code/bbtest02/.meteor/local/build/main.js --keepalive

  • You need to send kill -s USR1 to process2

  • Run the node inspector and you will see the server code

From my first attempt, I modify the last line when running the meteor script in / usr / lib / meteor / bin / meteor to

exec "$DEV_BUNDLE/bin/node" $NODE_DEBUG "$METEOR" "$@" 

and run NODE_DEBUG=--debug meteor on the command line. This only puts the -debug flag in process1, so I only see meteorite files in node -inpector and cannot find my code.

Can anyone check this out on a Windows and Mac computer?

+73
debugging server-side meteor
Jun 14 2018-12-12T00:
source share
12 answers

In Meteor 0.5.4, this has become much simpler:

First, run the following commands from the terminal:

 npm install -g node-inspector node-inspector & export NODE_OPTIONS='--debug-brk' meteor 

And then open http://localhost:8080 in your browser to view the -spector node console.

Update

Starting with Meteor 1.0 you can simply type

 meteor debug 

which is essentially a shortcut to the above commands, and then launches the node inspector in your browser, as mentioned.

Update

Meteor 1.0.2 adds a console or shell. This can be useful for outputting variables and running commands on the server:

 meteor shell 
+83
Feb 22 '13 at 10:20
source share

Meteor apps are Node.js apps When you launch the Meteor application using the meteor [run] command, you can configure the NODE_OPTIONS environment NODE_OPTIONS to run node in debug mode .

Examples of values ​​for NODE_OPTIONS environment NODE_OPTIONS :

  • --debug
  • --debug=47977 - specify port
  • --debug-brk - break in the first statement
  • --debug-brk=5858 - specify the port and split the first statement

If you export NODE_OPTIONS=--debug , the entire meteor command launched from the same shell inherits the environment variable. In addition, you can enable debugging for only one run, with NODE_OPTIONS="--debug=47977" meteor .

To debug, run the node-inspector in a different shell, and then go to http://localhost:8080/debug?port=<the port you specified in NODE_OPTIONS> , regardless of what the node-inspector tells you to start.

+14
Feb 14 '13 at 11:07
source share

To run node.js in debug mode, I did it like this:

  • open /usr/lib/meteor/app/meteor/run.js
  • before

     nodeOptions.push(path.join(options.bundlePath, 'main.js')); 

    add

     nodeOptions.push('--debug'); 

The following are additional practical steps for attaching to the eclipse debugger:

  • use '--debug-brk' instead of '--debug' here, because it is easier for me to attach node.js using eclipse as a debugger.
  • add 'debugger;' in the code where you want to debug. (I prefer this method personally)
  • launch a meteorite in the console
  • attach to node.js in eclipse (V8 tools, connect to localhost: 5858)
  • run, wait until the debugger is hit.

when you start the meteor in the folder of your meteor application, you will see that the "debugger is listening on port 5858" in the console.

+8
Jul 29 '12 at 13:15
source share

In Meteor 1.0.3.1 (Sergey Simonchik’s answer is updated)

Start your server using meteor run --debug-port=<port-number>

Point browser http://localhost:6222/debug?port=<port-number>

Where <port-number> is the port you specified.

In the code add debugger; where you want to set a breakpoint.

Depending on where the debugger; is called debugger; , it either breaks into the window of your client browser or server with an open inspector.

+8
Feb 18 '15 at 0:56
source share

I like to set breakpoints through the GUI. This way, I need to remember to remove any debugging code from my application.

Here's how I managed to do this on the server side for my local meteor application:

 meteor debug 

Launch the application this way.

Open Chrome to the address that it will provide you. You may need to install https://github.com/node-inspector/node-inspector (this may happen bundled with Meteor now not sure)

You will see some strange internal meteorite code (not the application code you wrote). Click the button to run the code. This code just starts your server to listen for connections.

Only after pressing the play button will you see a new directory in the folder structure of the debugger called "application" . They have the files of your meteorite project. Set a breakpoint where you want.

Open the local address of your application . This will run your code on the server side and you can get to the breakpoint!

Note: you need to open the inspector again and go through this process every time your application restarts!

+6
Nov 02 '15 at 16:11
source share

As in the case of Meteor 1.0.2, the best way to debug on the server side is directly through the new built-in shell: with the launch of the meteor shell server. More details here: https://www.meteor.com/blog/2014/12/19/meteor-102-meteor-shell

+5
Jan 29 '15 at 5:19
source share

I am not sure why it does not work for you.
I can use it by following these steps on the console (Mac).

 $ ps $ kill -s USR1 *meteor_node_process_id* $ node-inspector & 

The above steps are listed at https://github.com/dannycoates/node-inspector . It is designed to connect a node inspector to start the node process.

+4
Jun 14 '12 at 18:21
source share

I wrote a small meteor packet called the meteor inspector, which simplifies the use of the node inspector for debugging meteorite applications. It internally manages the life cycle of the node-inspector and therefore, the user does not need to restart the debugger manually after changing some files.

For more information and specific instructions for use, see https://github.com/broth-eu/meteor-inspector .

+3
Dec 14 '13 at 10:07
source share

for meteor 1.3.5.2, run

meteor debug --debug-port 5858 + nn is a nonzero number, this will cause the 8080 + n node inspector to be used as the web port.

+3
Jan 05 '17 at 11:14
source share

WebStorm , a powerful IDE that is free for open source developers, makes debugging the server side a lot easier.

I tested it on Windows and the configuration was painless - see my answer .

+2
Feb 12 '14 at 2:03
source share

The inspector who solves my problems is the console of the meteorite server. Here is the process that I completed to install it:

  • In the project folder, add the server-eval smart package:

     mrt add server-eval 

    For Meteor 1.0:

     meteor add gandev:server-eval 
  • Restart the meteorite.

  • Download the crx file for the Chrome extension from here .
  • Open the extensions page in Chrome and drag the crx file crx the extensions page.
  • Restart Chrome.
  • Check web inspector for server side code:

    enter image description here

Compared to the node inspector, I have a clearer conclusion.

+2
Jul 01 '14 at 23:11
source share

If you prefer to use the official nodeJS debugger , you can call NODE_OPTIONS='--debug' meteor , and then (in another shell) node debug localhost:5858 .

+1
Nov 18 '14 at 17:44
source share



All Articles