I am trying to debug my node app in WebStorm and keep getting a 'Closed explicitly' error when I start the debug session.
I am pointing my Node interpreter to the version of node installed on my machine and the working directory and index file to the route file of my application.
Note that I am trying to use node version 6.5.0, debug works fine when running against 5.4.0 (for another application).
Be gentle
This can happen when your Nodejs app is immediately exiting (e.g. due to a syntax error), thus it won't accept connections for Nodejs remote debugging.
Related
I am trying to deploy a small Node.js application to Heroku, and then have the Heroku Scheduler run the application every 10 minutes. Our customers former supplier who built this application also hosted it on Heroku, so there should be no need to change anything in the sourcecode, that I have received. Nevertheless I am getting the following error from the Heroku log.
2018-05-09T07:26:07.710882+00:00 app[api]: Starting process with command `fetch` by user scheduler#addons.heroku.com
2018-05-09T07:26:11.124833+00:00 heroku[scheduler.2653]: Starting process with command `fetch`
2018-05-09T07:26:11.718182+00:00 heroku[scheduler.2653]: State changed from starting to up
2018-05-09T07:26:13.647479+00:00 heroku[scheduler.2653]: State changed from up to complete
2018-05-09T07:26:13.629258+00:00 heroku[scheduler.2653]: Process exited with status 126
2018-05-09T07:26:13.542885+00:00 app[scheduler.2653]: bash: /app/bin/fetch: /usr/local/bin/node: bad interpreter: No such file or directory
Apparently there's an issue with the 'Shebang' line in my fetch file which runs my index.js file:
#!/usr/local/bin/node
var path = require('path');
require(path.join(__dirname, '../index')).start();
I am rather new to Node.js and Javascript, so I'm not sure I fully understand the purpose of the 'Shebang' line. But I'm guessing it is pointing to a wrong location or something like that? How do I figure out, what to change in this line?
Shebang line tells which interpreter to use to run the file. Error you receive tells that node is not installed in location shebang points to. Using #!/usr/bin/env node usually works.
You should not have a need for any "shebang" line in your "fetch" file.
I suggest you simply remove the #!/usr/local/bin/node line, and specify the following as your Heroku Scheduler command:
node <path_to_fetch.js>
That should get heroku scheduler to launch your node.js app in a one-off dyno, provided you have a node.js buildpack in your app.
Use the instructions here to check if you have a node.js buildpack in your app, and to add it if necessary.
That said, if you really want to run your app with a "shebang", change it to #!/usr/bin/env node. In that case, omit the word node in your Heroku scheduler command.
I have a stand alone node js script.
I am doing some local task with that script. I want to debug that script in chrome dev tools. I know I can debug it locally via putting debugger in code but do not want to do that.
On nodejs docs I saw that it has some options like -
V8 Inspector Integration for Node.js# NOTE: This is an experimental
feature.
V8 Inspector integration allows attaching Chrome DevTools to Node.js
instances for debugging and profiling.
V8 Inspector can be enabled by passing the --inspect flag when
starting a Node.js application. It is also possible to supply a custom
port with that flag, e.g. --inspect=9222 will accept DevTools
connections on port 9222.
To break on the first line of the application code, provide the
--debug-brk flag in addition to --inspect.
$ node --inspect index.js
But when I do that it gives me error like -
$ node --inspect index.js
node: bad option: --inspect
My node version is:
$ node --version
v4.4.7
You need node 6.3 or above --inspect is not supported in 4.4.7
#Andrey
Thanks a lot for pointing out that I was scratching my head for a long time on this.
#dan
Thanks for node-inspector suggestion.
I am just posting an answer in case someone else might stuck on this.
I have installed node-inspector and,
This is what I'm doing to start the debugger..
Opened one terminal and
$ node-inspector --no-preload
Node Inspector v0.12.5
Visit http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 to start debugging.
In another terminal,
$ node --debug-brk app.js
debugger listening on port 5858
Intially I was using just --debug. But it was not hitting the breakpoints and was going through all code. Then I used --debug-brk. Using --debug-brk caused node to break on the first line of app and waited for a debugger to hit breakpoints.
Then started Google Chrome and went to
http://127.0.0.1:8080/debug?port=5858
Here chrome dev tools was opened and I was able to put break point and debug the code.
Node Inspector works pretty well. Also keep in mind Node 7 has native node debugging, even supports live-edit! Here's a gif of it in action: Chrome DevTools: Live edit running Node.js code with hotswapping
I'm completely new to nodeJs, and just to learn step by step. I managed to download, run nodeJs via the CMD and tested by creating file, all works fine. The problem now is when I want to tell nodeJs to display the output on the browser instead. I simply followed the tutorial but I'm getting runtime error. I suspect the port is somewhat wrong. Which port no I should use here, is it my localhost port which is 80, I tried it to no avail.
Here's the error message:
Referred here:Using node.js as a simple web server
All I want is to be able to see the output in the browser via nodeJs. I think the port 9999 is meant for tcp connection as I'm learning for real-time app.
You're not using NodeJS to run your code. To run your code using NodeJS, run them with node:
node c:\projects\test\helloweb.js
The reason what you tried didn't work is that typing c:\projects\test\helloweb.js in cmd.exe and pressing Enter will not run the code in a browser, or in NodeJS. It will try to run it using whatever application you have associated with .js files. The Windows default, which is what your computer is using, is to use Windows Script Host (as you can see in your error message). WSH provides a runtime environment that's quite different from NodeJS and quite different from a browser.
If you read the dialogue carefully you'll see its title is "Windows Script Host", not Node. In fact Node is a command-line tool that doesn't launch dialogues or other widgets. Your screenshot clearly shows you were doing it just fine and then eventually forgot to type node in your command:
FYI, Windows Script Host is a tool that's similar to Node (a server-side ECMAScript engine) but belongs to another vendor (Microsoft), uses a different ECMAScript implementation (JScript) and possibly hasn't been updated in 10 years. That means that features and available libraries are completely unrelated to those in Node.
I have moved an existing node.js + express project to VS because I prefer the IDE over JetBrains for now (used VS for years, only peeked into Webstorm).
I used NTVS new project->from existing sources and all files were imported successfully.
Afterwards, I opened the project settings of my project and set the node.exe arguments to bin\www, startup file for express.
When I press F5 (debug) I get the console.log messages I have put into the www and app.js files in the opening command prompt, and it looks like the server is running (cannot confirm, I want to debug if everything is working), but the VS debugger directly exits again, it also does not open any page in the browser I selected for debugging.
My node app actually is a REST webservice, so I want to test different URLs with different parameters.
Also, I cannot access the app on the port I specified, though when I directly start it from node.exe I can, even though the command prompt is still open.
(I have NTVS and WebEssentials installed - some operations take a long long time, but I attribute this to NTVS being still an early version.)
Question: how does the Visual Studio debugger stay connected to the node.js application so I can use breakpoints and use any browser then to connect and test different URLs? (Even a breakpoint put on the console.log that gets printed during startup is not being triggered.)
For everyone who asks receives, and the one who searches finds....
(and yes, I did spend a long time searching and trying before posting here..)
Kind of nice to debug node.js server with VS..
hope this helps someone
Edit: The arguments to node.exe can be hard to read in the image. It must be
--debug=<portno>
that is with two dashes (and not just one) to specify the debug port.
Not so much knowledge on expressjs but with a recent release of NTVS 1.0 Alpha, I did find it supports remote debugging which can be also used to debug nodejs app running locally - anyway haven't tried if it works with nodejs app + expressjs but it should.
I followed the step in this video https://youtu.be/-ir9ZB8lUg4 which is
Run your nodejs with node.exe RemoteDebug.js <your_javascript_file>.
RemoteDebug.js has come when you install NTVS.
In Visual Studio, select Debug > Attach to Process
Select Node.js remote debugging for Transport
Enter localhost:5859 for Qualifier
Click Attach
This will put Visual Studio in debugging mode which you can set a breakpoint, do step-in/step-out, very same experience when you use VS to debug .NET app.
Its pretty straight forward with NTVS, you can download required version for your windows from github here
Once you install NTVS, NodeJS project templates will be added
Now, Goto File->New project -> Basic NodeJS Express 3 application (it will be available in javascript project templates)
Now just goto debug and select Start Debugging, add breakpoints where ever required and you can start debugging
My Node.js application runs correctly locally but it has errors once deployed to Heroku.
I cannot use node-inspector to debug as it requires three ports, and Heroku allows only one port.
https://discussion.heroku.com/t/how-to-debug-node-on-heroku-using-something-like-node-inspector/477/6
I cant use the debugger built into Node.js because I need a CLI to issue debugging commands.
http://nodejs.org/api/debugger.html#debugger_debugger
What is the best strategy for interactively debugging a Node.js application on Heroku?
Found One-Off Dynos, which allow:
Running a console (also known as a REPL shell) to run arbitrary code or inspect the app’s models against the live database. (e.g. rails console, irb, or node)
https://devcenter.heroku.com/articles/one-off-dynos#types-of-one-off-dynos
I didn't have time to test, but this should let me run the built in node debugger.