I want to be able to drop a debugger statement (or something similar) right into my code and get a REPL when I run my tests so I can interact with my code to debug stuff.
I understand that Node (via V8) supports the debugger statement out of the box, but you have to run your code with certain flags (via node debug or node --debug or node --debug-brk -- I don't really understand the differences).
Mocha has these same flags as well, and when I run mocha debug I indeed get a debugger prompt in my terminal:
< Debugger listening on port 5858
connecting to port 5858... ok
break in node_modules/mocha/bin/_mocha:5
3 */
4
> 5 var program = require('commander')
6 , path = require('path')
7 , fs = require('fs')
debug>
But the breakpoint is in Mocha's code, not my breakpoint. This blog post says you're supposed to type run then continue to get to your breakpoint, but when I enter run it tells me "App is already running..." and when I enter continue it tells me "SyntaxError: Illegal continue statement".
It says "listening on port 5858" -- do I need to open a separate connection to that port from somewhere, like a browser or another terminal session?
I've seen some things about node-inspector, but I like to stay in the terminal as much as possible so I prefer a way to do this without opening a browser.
I'm new to JS, so please ELI5 :)
Also, if it's relevant, I'm actually using io.js, not Node proper
When the node/iojs debugger first starts up and connects it always breaks on the first line of whatever the script was that was passed into the interpreter.
Since you're already running your app, you do not need to type run here, but you can just type c to continue execution until your breakpoint has been it.
run is useful if the program terminates while you're in the debugger -- you can start it up again! (You can also do restart to restart the program within the debugger).
Related
I want to run a node application from my raspberry pi. The application is supposed to start on boot.
I have included the following lines in /etc/rc.local (before exit 0) :
cd /home/pi/PPBot
node bot.js > dev/null &
I first navigate to the correct folder and then run the bot from there. However the node application is not running when I reboot my raspberry pi. So it seems that rc.local is not executed or unable to execute the lines I provided.
I am looking for a solution so that the application will run at boot.
save this
[Unit]
Description=Node JS Script Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/node /path/to/hello_env.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
to /etc/systemd/system/ as nodescript.service
sudo systemctl daemon-reload
sudo systemctl start nodescript
if it worked, make it startup on boot
sudo systemctl enable nodescript
The examples I 've seen (like this one) used
cd /home/pi/PPBot
node bot.js < dev/null &
instead of
cd /home/pi/PPBot
node bot.js > dev/null &
Note the < instead of the >. As you can see here, the < redirects the Standard In (stdin), while the > redirects the Standard Output (stdout). And as described here,
< /dev/null is used to instantly send EOF to the program, so that it doesn't wait for input (/dev/null, the null device, is a special file that discards all data written to it, but reports that the write operation succeeded, and provides no data to any process that reads from it, yielding EOF immediately). & is a special type of command separator used to background the preceding process.
Since you havent used < dev/null, maybe your program is stuck and waits for some input. The & at the end makes your program run in the background. Try to not include it and see if your Rasberry Pi is still booting. If not, you know that your programs runs continously and blocks further booting; when you used the & sign, your program just failed in a separate process. In this case changing the > to < should help because your programs doesn't wait for input.
If the above doesn't work, update your question with the specific error message. You can view the boot log by using the command dmesg (display message).
In this case when you
cd /home/pi/PPBot
you are no longer in the root directory so when you run
node bot.js > dev/null &
it is looking for the dev folder at /home/pi/PPBot/dev
You will need to add a leading / to ensure it is accessing /dev
change
node bot.js > dev/null &
to
node bot.js > /dev/null &
Hi this problem just currently started happening and have never had this issue before. Every time I start up my express server it runs fine the first time. When I close the server in my git bash with control C it shuts down but when I try to start up the server again I get the EADDRINUSE error. This makes no sense at all and I have tried to use killall -9 node command without any success does anyone have any suggestions as to what might be going on.
EADDRINUSE error means that the port that your server is trying to use is already being used by something else. My suggestion would be to close all terminal windows first. Then start a completely new terminal window, and then try running the server. If that does not work, restart your laptop(I know this is tedious, but this usually works), and follow the above steps.
I am running Node.js and Socket.io for online chat.
I have created a file in:
/etc/init/example.conf
it has two lines:
start on startup
exec forever start /var/www/example.com/html/server.js //location of server file.
Whenever I start file upload in chat application, it crashes but instantly restarts.
Whenever I kill node process though, and start it manually - it works fine.
I also can't get any logs or anything from terminal as when it's auto started - it doesn't print me anything to terminal.
I am still new to Node.js and Linux in general.
Node.js is running on Express + Jade.
How do I determine specific cause?
I managed to solve my problem, after a bit of searching around I found out about tail command.
My issue was a bit harder to trace because Node.js was a process started by autostart so when I launched terminal and connected to server, process was just running in background basically and I wouldn't get any output (including exception messages).
Anyway, solution that worked for me was:
I typed
ps aux | grep node //to find PID of node process
then I went to following directory
cd /proc/[pid of running node service]/fd
In fd directory there are few objects you can get output from but if you want to attach and listen to servers output including uncaught exceptions, you need 1.
So:
tail -f 1
that way I was able to cause website to crash and see the output.
This feels really silly, but I can't get node inspector / node-debug to work.
The instructions say to do npm install then to run node-debug web.js. So I did that. Now I have a lovely browser window open showing me my code with breakpoints... and no idea which url to use to actually access the code.
The inspector is at http://localhost:8080/debug?port=5858 and the terminal says:
> node-debug web.js
debugger listening on port 5858
Node Inspector is now available from http://localhost:8080/debug?port=5858
Debugging `web.js`
...
I've tried hitting up localhost:5000 (which is my express.js port) but that either fails if I don't have a separate node web.js instance running, or it succeeds if I have the other one running but doesn't trip any of the breakpoints in the inspector.
When I go to http://localhost:5858/, I get:
Remote debugging session already active
When I go to http://localhost:8080/, I get:
Cannot GET /
(the / path totally works on my server in general.)
By default node-debug starts app in --debug-brk mode.
This stops your app at first line (express not started).
You can use node-debug --no-debug-brk see the node-debug --h for more info.
Agh. Okay, looked at some more questions before I got this posted. Looks like the problem was just that I wasn't running the original instance in debug mode. Nobody had told me I had to, so I just didn't know otherwise!
What's working for me now:
> node debug web
then in a different terminal
> node-debug web.js
I'm trying to configure Webstorm for using the node.js' debugger.
I've set the enviroment and everything, the app is running fine with the run button, but with the debugger button it just hangs up writing only:
/usr/bin/node --debug-brk=52006 --debug-brk node.js
debugger listening on port 52006
and it doesn't work or writes anything on the output.
Any idea of what is missing? I've already installed node-inspector and everything.
EDIT:
After sometime that I run the code, I get:
Failed to open socket on port 52708, waiting 1000 ms before retrying
Problem solved with the help of JetBrains. In a few words, I used cluster creating child nodes that weren't connected to the debugger.
Full explanation here: https://intellij-support.jetbrains.com/tickets/13630