Interactively debugging a Node.js application on Heroku? - javascript

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.

Related

What is the role of Node.js in React-Native?

I'm trying to understand the development process of React-Native, so I've found information about Metro, And then I've read/watch this Metro video):
Metro is the development platform for React Native and it does that by
exposing an HTTP server so clients, in this case, emulators can
communicate with it and it also exposes a Websocket server so it can
push updates into the clients.
The docs talk about the "React Native Packager" (now called Metro, according to the video) which runs on port 8081, so that is the HTTP server that starts when we type react-native run-android for example?
Regarding the Websocket I still need to read more.
The documentation says we're running our JavaScript code in two environments, depending if we're in debug mode or not, which I understood. But this article confused me a little bit, says:
No. 4 You Code Does Not Run on Node.JS: The JavaScript runtime you’ve got is ether JavaScriptCore (non-debug) or V8 (debug). Even
though you can use NPM and a node server is running on the background,
your code does not actually run on Node.JS. So you won’t be able to
use of the Node.JS packages. A typical example is jsonwebtoken, which
uses NodeJS’s crypto module.
And, then I've read things like:
React Native uses Node.js, a JavaScript runtime, to build your
JavaScript code.
Node.js is a server-side JavaScript runtime environment. React
Native ships with some tools that are written for Node.js.
Node.js is an open source platform built on Chrome's JavaScript
runtime; it offers a way to easily build fast, scalable
programs. Node.js allows you to run JavaScript in Terminal, and helps
create modules.
In this article, it says:
Download node.js from nodejs.org. This JavaScript runtime gives you
access to npm, which is a convenient tool created by the node.js
project that you can use to manage open source packages. Make sure
that you download the latest LTS (Long Term Support) version of
node.js. Also included with this download is a development server
called the Metro bundler, which provides live updates when debugging.
So:
The role of Node.js in RN is to only access npm and manage the packages? and is Metro is includes in Node.js? Am I missing/confusing something? Thank you.
There are four types of JavaScript you'll write in todays environments:
1) Clientside browser JavaScript:
That's what gets sent to webbrowsers when they visit your webpage, it then gets executed in the browser at the clientside. As you want the JS to load fast and run on all kinds of browsers, you usually use transpilers to turn the modern ESnext you write into a minified version with better support.
2) Clientside native JavaScript:
Most devices do have a native JS runtime, therefore you can ship JS files with your Android / iOS / Desktop application and then start them there. These engines also support adding hooks from JavaScript into your native code, that's how React Native does provide it's APIs.
3) Serverside NodeJS JavaScript:
NodeJS is a runtime you'll use to run servers.
4) Buildscripts running on NodeJS:
You can use JavaScript to generate JavaScript files. That's how you bundle the files for (1) and (2) (maybe also (3)).
Now metro is a serverside buildscript (on NodeJS) that you can use to either a) start a server that serves your JS as a webpage (1 & 3), or b) that bundles your JS in a native App that you can install on your device (2).
The role of Node.js in RN is to only access npm and manage the packages?
No. metro is itself a package that you then run on NodeJS.

How can I prevent multiple applications being served at once by AngularCLI?

Using
Angular CLI: 1.5.2
Node: 6.10.1
in a Mac OS Sierra,
I have installed several web applications so far. Anytime I do ng serve. All of the applications that I have installed in the past are served.
I guess it's the normal behavior. But I don't need that...
How do I "uninstall" old applications that I don't want anymore to be run?
Edited to answer comments:
I run npm start from one of the applications that get served. Actually, I run it from the only application that I'd like to be started. However, as I said, all of the applications get started up.
Some other facts:
They run under the same port (4200).
The first application I installed runs without any context in the URI. (http://localhost:4200)
The rest of the applications are started under the same 4200 port, but I need to complete the URI with the actual context.

Node.js emits runtime error when listen to port 9999

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.

Difficulty in deploying Node.JS + Grunt based web application from terminal

I have a website which is developed based on Node.JS and uses grunt to be run.
I want to deploy it on my aws server. So, i installed node.js and all its dependencies and modules, configured database etc, and i am able to run it from terminal.
First i used
grunt build
and then
grunt
and website is running and up without any problem.
My question is that how should i deploy these kind of websites, so it always is running and listening to the port? That is because whenever i close the terminal (Putty), it will stop working.
I tried using these commands to run it in the background but didn't work :
grunt &
alnd also
(grunt &)
but whenever i exit the terminal (putty) , web server stops working.
Can anybody please help me with that? How can i make grunt running even after closing the terminal?
And how node js + grunt websites will be deployed on the server in general?

How to debug node.js application with Visual Studio 2013 and Node Tools NTVS

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

Categories

Resources