programing tip

Meteor : 서버 측에서 디버그

itbloger 2020. 10. 12. 07:18
반응형

Meteor : 서버 측에서 디버그


누구든지 서버 측 코드를 디버깅하는 좋은 방법을 알고 있습니까? Node.js 디버그 활성화를 시도한 다음 node-inspector를 사용했지만 내 코드가 표시되지 않습니다.

나는 console.log를 사용하지만 이것은 매우 비효율적입니다.

업데이트 : Linux 컴퓨터에서 다음 절차가 작동하는 것을 발견했습니다.

  1. Meteor를 실행하면 두 개의 프로세스가 생성됩니다.

    프로세스 1 : / 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

  2. process2에서 kill -s USR1을 보내야합니다.

  3. 노드 검사기를 실행하면 서버 코드를 볼 수 있습니다.

첫 번째 시도에서 / usr / lib / meteor / bin / meteor의 meteor 시작 스크립트의 마지막 줄을 다음과 같이 수정합니다.

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

실행 NODE_DEBUG=--debug meteor명령 프롬프트에서. 이것은 process1에 --debug 플래그 만 놓았으므로 node-inspector에서 meteor 파일 만보고 내 코드를 찾을 수 없습니다.

누군가 Windows 및 Mac 컴퓨터에서 이것을 확인할 수 있습니까?


Meteor 0.5.4에서는이 작업이 훨씬 쉬워졌습니다.

먼저 터미널에서 다음 명령을 실행하십시오.

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

그런 다음 http://localhost:8080브라우저에서 열어 노드 검사기 콘솔을 봅니다.

최신 정보

Meteor 1.0부터는

meteor debug

이것은 본질적으로 위의 명령에 대한 바로 가기이며, 언급 한대로 브라우저에서 노드 검사기를 실행합니다.

최신 정보

Meteor 1.0.2에서는 콘솔 또는 셸이 추가되었습니다. 변수를 출력하고 서버에서 명령을 실행하는 것이 유용 할 수 있습니다.

meteor shell

Meteor 앱은 Node.js 앱입니다. meteor [run]명령 으로 Meteor 앱을 실행할 때 디버그 모드에서 시작 하도록 NODE_OPTIONS환경 변수를 구성node 할 수 있습니다 .

NODE_OPTIONS환경 변수 값의 :

  • --debug
  • --debug=47977 -포트 지정
  • --debug-brk -첫 번째 진술 중단
  • --debug-brk=5858 -포트를 지정하고 첫 번째 명령문에서 중단

이면 동일한 쉘에서 실행되는 export NODE_OPTIONS=--debug모든 meteor명령이 환경 변수를 상속합니다. 또는를 사용하여 한 번의 실행에 대해서만 디버깅을 활성화 할 수 있습니다 NODE_OPTIONS="--debug=47977" meteor.

디버그하려면 node-inspector다른 셸에서 실행 한 다음 실행 하라는 메시지 http://localhost:8080/debug?port=<the port you specified in NODE_OPTIONS>에 관계없이 로 이동하십시오 node-inspector.


디버그 모드에서 node.js를 시작하려면 다음과 같이했습니다.

  1. /usr/lib/meteor/app/meteor/run.js를 엽니 다.
  2. 전에

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

    더하다

    nodeOptions.push('--debug');
    

다음은 디버거 이클립스를 연결하는 추가 실용적인 단계입니다.

  1. eclipse를 디버거로 사용하여 node.js를 연결하는 것이 더 쉽기 때문에 여기에서 '--debug'대신 '--debug-brk'를 사용하십시오.
  2. '디버거'추가 디버그하려는 코드에서. (개인적으로이 방식을 선호합니다)
  3. 콘솔에서 유성을 실행
  4. Eclipse에서 node.js에 연결 (V8 도구, localhost : 5858에 연결)
  5. 실행, 디버거가 히트 할 때까지 기다립니다

meteor 앱 폴더에서 meteor를 시작하면 콘솔 " debugger listen on port 5858 "이 표시됩니다.


Meteor 1.0.3.1 (Sergey.Simonchik 답변 업데이트)

다음으로 서버 시작 meteor run --debug-port=<port-number>

브라우저를 http://localhost:6222/debug?port=<port-number>

<port-number>지정한 포트는 어디에 있습니까 ?

코드 debugger;에서 중단 점을 설정할 위치를 추가 하십시오.

debugger;호출 되는 위치에 따라 검사기가 열린 상태에서 클라이언트 또는 서버 브라우저 창에서 중단됩니다.


GUI를 통해 중단 점을 설정하는 것을 좋아합니다. 이렇게하면 내 앱에서 디버깅 코드를 제거 할 필요가 없습니다.

이것이 내 지역 유성 앱을 위해 서버 측에서 관리 한 방법입니다.

meteor debug

이런 식으로 앱을 시작하십시오.

제공된 주소로 Chrome을 엽니 다. https://github.com/node-inspector/node-inspector 를 설치해야 할 수도 있습니다 (지금 Meteor와 함께 번들로 제공 될 수 있습니까? 확실하지 않음)

이상한 내부 유성 코드 (사용자가 작성한 앱 코드가 아님)가 표시됩니다. 코드를 실행하려면 재생누르십시오 . 이 코드는 단순히 연결을 수신하기 위해 서버를 시작합니다.

Only after you press play you'll see a new directory in your debugger folder structure called "app". In there are your meteor project files. Set a breakpoint in there one the line you want.

Open the local address of your app. This will run your server side code and you you should be able to hit your breakpoint!

Note: you have to reopen the inspector and go through this process again each time your app restarts!


As of Meteor 1.0.2 probably the best way for server-side debugging is directly via the new built-in shell: with running server run meteor shell. More info here: https://www.meteor.com/blog/2014/12/19/meteor-102-meteor-shell


I am not sure why it was not working for you.
I am able to use it by following steps on console (Mac).

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

Above steps are mentioned on https://github.com/dannycoates/node-inspector. It is for attaching node-inspector to running node process.


I wrote a small meteor package called meteor-inspector which simplifies the use of node-inspector to debug meteor apps. It internally manages the lifecycle of node-inspector and hence, the user does not need to restart the debugger manually after some files have changed.

For more details and concrete usage instructions take a look at https://github.com/broth-eu/meteor-inspector.


for meteor 1.3.5.2, run

meteor debug --debug-port 5858+n n is a non-zero number, this will cause node-inspector use 8080+n as web port.


WebStorm, the powerful IDE free for open source developers, makes it much easier to debug server-side.

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


A inspector that solve my issues is meteor server console. Here is the process I followed to install it:

  1. In your project folder, add the smart package server-eval:

    mrt add server-eval
    

    For Meteor 1.0:

    meteor add gandev:server-eval
    
  2. Restart meteor.

  3. Download crx Chrome extension file from here.
  4. Open extensions page in Chrome and drag crx file to extensions page.
  5. Restart Chrome.
  6. Check the web inspector out to eval server side code:

    enter image description here

In comparison with node-inspector, I have a clearer output.


If you prefer to use nodeJS' official debugger you can call NODE_OPTIONS='--debug' meteor and then (on a different shell) node debug localhost:5858.

참고URL : https://stackoverflow.com/questions/11034941/meteor-debug-on-server-side

반응형