Is it possible to monitor / retrieve variable values in use on NodeJS server? - node.js

What tools can you use to monitor or access data in use on a Node server? A comparison would be using the Javascript Console for a browser and being able to console.log a variable value to the console or execute methods. Is there something similar you can do with a NodeJS server?
Edit: An example; if I deployed my server to an AWS ec2 instance could someone managing the datacenter theoretially access my server and monitor/view the data in use? If so, how?

I think this will help you in debugging
http://techblog.netflix.com/2015/12/debugging-nodejs-in-production.html

Related

Can I run a front-end and back-end on Netlify?

I want to practice creating my own RESTful API service to go along with a client-side application that I've created. My plan is to use Node and Express to create a server. On my local machine, I know how to set up a local server, but I would like to be able to host my application (client and server) online as part of my portfolio.
The data that my client application would send to the server would not be significant in size, so there wouldn't be a need for a database. It would be sufficient to just have my server save received data dynamically in an array, and I wouldn't care about having that data persist if the user exits the webpage.
Is it possible to use a service like Netlify in order to host both a client and server for my purposes? I'm picturing something similar to how I can start up a local dev server on my computer so that the front-end can interface with it. Except now I want everything hosted online for others to view. I plan to create the Express server in the same repo as the front-end code.
No, Netlify doesn't allow you to run a server or backend. However, they do allow you to run serverless functions in the cloud. These can run for up to 10 sec. at a time. Furthermore Netlify also have a BETA solution called "background functions" That can run for up to 15 minutes. But honestly for a RESTful API there sure would be better solutions out there?
If you are still looking for the Netlify for Backend you can consider Qovery. They explained here why it is a good fit for their users.

Database Switching in Node Application for each client

I have multiple clients on the system and each of the clients will have an individual database. but I don't see any solutions to serve the respective database for the client with each API.
Please guide me to serve API call with client respected database in Node.
This is the perfect use of environment variables. You essentially will pass these in to whatever deployment you'll be using, and then you can access them with the dotenv package and process.env

Can a web application be developed using hybrid technologies?

Is it possible to develop a web application using a mix of technologies like servlet and nodejs? Using servlets somewhere and nodejs at some other place when required.
Yes. Read about microservices. Docker can come in handy;)
Yes, consider these two use cases.
Use case 1 (Sub Domains)
You want www.example.com to use PHP & MySQL for Wordpress, api.example.com to run on Nodejs & MongoDB and coders.example.com to use Servlets.
Here you'd code and start all servers (PHP, Nodejs & Java server) on their specific & different ports and configure a frontend server (like Nginx) to receive and redirect requests according to the subdomains specified.
Use case 2 (In-App)
You want a request to come inside your Nodejs application get processed and then trasfer data to another process (a running Java app) and wait for a response back so it can process to user.
This can be accomplished by Message ques or HTTP/web services.
Both of these services will help you share your data back and forth.
Read more on Message ques
Read more on HTTP/Web services
References
Is it possible for node.js to import a java library
https://www.quora.com/How-does-Node-js-communicate-with-Java-applications
https://www.quora.com/topic/Message-Queuing

How to direct a user to an available websocket server when she logs in to my multi-server Node.js app?

This is more like a design question but I have no idea where to start.
Suppose I have a realtime Node.js app that runs on multiple servers. When a user logs in she doesn't know which server she will be assigned to. She will just login, do something and logout and that's it. A user won't be interacting with other users on a different server, nor will her details be stored on another server.
In the backend I assume the Node.js server will put the user's login details to some queue and then when there is space it will assign this user to an available server (A server that has the lowest ping value or is not full). Because there is a limit number of users on one physical server when the users try to login to a "full" server it will direct her to another available server.
I am using ws module of node.js. Is there any service available for this purpose or do I have to build my own? How difficult would that be?
I am not sure how websocket fits into this question. Ignoring it. I guess your actual question is about load balancing... Let me try paraphasing it.
Q: Does NodeJS has any load balancing feature that I can leverage?
Yes and it is called cluster in NodeJS. Instead of the traditional one node process listening on a single port, this module allows you to spawn a group of node processes and have them all binded to the same port.
This means is that all the user know is only the service's endpoint. He sends a request to it and 1 of the available server in the group will serve him whenever possible.
Alternatively using Nginx, the web server, as your load balancer is also a very popular approach to this problem.
References:
Cluster API: https://nodejs.org/api/cluster.html
Nginx as load balancer: http://nginx.org/en/docs/http/load_balancing.html
P.S
I guess the key word for googling solutions to your problem is load balancer.
Out of the 2 solutions I would recommend going the Nginx way as it is a much scalable approach
Example:
Your Node process could possibly be spread across multiple hosts (horizontal scaling). The former solution is more for vertical scaling, taking advantages of multi-cores machine.

Node.JS/Meteor on multiple servers serving the same application

When coming to deploy Node.JS/Meteor for large scale application a single CPU will not be sufficient. We also would like to have it on multiple servers for redundancy.
What is the recommended setup for such deployment ? how does the load balancing works ? will this support the push data technology for cross servers clients (one client connects to server 1, 2nd client connects to server 2 and we would like an update in client one to be seen in client 2 and vice versa).
Thanks Roni.
At the moment you just need to use a proxy between them. The paid galaxy solution should help but details are scarce at the moment as the product isn't out yet.
You can't simply proxy (normally using nginx, etc) between two servers as each server will store the user's state (i.e their login state) during the DDP Session (the raw wire protocol meteor uses to transmit data).
There is one way you could do it at the moment. Get meteorite and install a package called meteor-cluster.
The package should help you relay data between instances and relay data between the instances via Redis. A youtube video also shows this and how to set it up.
An alternative solution is to use Hipache to manage the load balancing. You can use multiple workers (backends) for one frontent, like so:
$ redis-cli rpush frontend:www.yourdomain.com http://address.of.server.2
$ redis-cli rpush frontend:www.yourdomain.com http://address.of.server.2
There is more information on how to do this in the git page I linked to above, there is a single config file to edit and the rest is done for you. You may also want to have a dedicated server for MongoDB.

Resources