nodejs for background process, not a http server - node.js

Im new to nodejs, i am looking for a way to create a nodejs process that can run in the background. All the example I can find is to create a node http server. I don't need to listen for any web request i just need to startup a process and have it listen to a message queue.

NodeJS has enough API to be used for versatile tasks, not just HTTP Servers. You have two problems to solve:
Run Node process continuously. So, you'd need some equivalent of http.listen() so the process just don't exit. Whatever you intent to do, you'd probably need Node waiting for some external events.
Run node as a daemon or service. There are plenty of modules to help, foreman, pm2. You can make this process auto-start by using upstart on linux machines and node-window for windows.

Related

Can you launch electron app from nodejs and have it communicate back and forth?

I want to create GUI for terminal app. It'd be nice if I could code it with js/css/html. Electron seems like a good candidate. Is it possible, if yes how, to launch an electron app, have it talk to nodejs process running in background.
At this point I'm exploring different options.
Electron comes with NodeJs support. You don't need to run a background process to do that. But if that is required you can do this via a socket connection (something like websockets). Here is a good candidate for that.
Why you are creating NodeJS process separately. see when you launch an Electron application you will have two process i.e. main Process and render process. if you want you can create more then 1 renderer process.
in each process i.e. whether it is renderer or main process all NodeJS api is working .
and you can communicate with other process using ipc Communication.
Hope it will work

What is the best node process manager for Windows Server?

Our team maintains a Node-Express API in a Windows Server environment.
We've struggled to find a reliable process manager.
The Express js site lists some favored pm's, but they all seem Linux-optimized (Forever, PM2, SystemD, Strong-PM).
None of them will create a windows service to revive the process after server reboots without another module like node-windows or pm2-windows-service (based on node-windows). Node-windows works but it requires manual intervention to kill node processes when you stop the service.
Any advice out there on best process managers for maintaining a node process in Windows?
Note: I've got another question out there where I'm trying to debug our implementation of PM2: Why is PM2 not launching my Node process?

Can we use Apache Server for server side rendering of angular web apps or we have to stick with NodeJs

Currently I am running NodeJs server as background process in the host machine to achieve sender side rendering for my angular app.
On Linux for e.g. npm rum server & (ampersand is to put process in background)
But I am looking for solution like Apache Server that manages it start/stop with host reboot.
I think the best way for you to acheive what you're looking for is to use a management solution like PM2 or Forvever. These will pretty easily manage your solution in the background for you.
Rather than apache/nginx managing start stop of your node application, you may create service to run your node application. It will run without any manual intervention.
Start your Node app on some other port than 80, as your main web server might be running on that port.
Create a service file in /etc/init to start your Node app
Configure apache/nginx with reverse proxy to the node applicaiton
Start both of the services: 'service start nodeapp.conf' and 'service start apache2'
This would make your life for handling these services pretty easy.
Yes. You should be able to.
Start by creating a proper deployment directory - https://angular.io/guide/deployment
Then copy/ftp/whatever to the web server.
The tricky part is in your route controllers, etc. and getting all of the paths right if you end up deploying into a different directory than what you developed for.
You need to use Apache/Ngnix with NodeJS using proxy.
Look into this link, if this helps:
https://blog.daudr.me/painless-angular-ssr/

Starting nodejs asynchronous from Jenkins

I am currently implementing some mock http host using a node.js server. This server should be started by a jenkins CI job. After its started integration tests from JMeter should be performed and afterwards the node.js server should be shut down.
Right now i am having the problem that i can without problem start the node.js server as well as the jmeter test file alone. The problem is, that the node.js execution blocks the Jenkins Job and therefore the JMeter tests which are launched after Node are never actually started. Therefore i was wondering if there is a way to start a node.js server in the background, let it listen until the JMeter tests are over then shut it down again.
I guess the shutdown can be achieved using some special request to the nodejs server, but the main problem is that starting the nodejs http server blocks the entire jenkins process and thus the JMeter tests never start.
Is there a way to tell Jenkins that it should start the nodejs server but should not wait for it to end? Thanks in advance, Cromon

Run at startup and monitor redis and node.js processes

I want to deploy node.js app which depends on redis. Both processes will run on the same VPS. There are plenty of examples on how to daemonize and monitor node and I've also found some uncommented configuration for redis. How do I put it together? Can I just combine these two snippets in one monitrc file?
You could use Supervisord to orchestrate the launch of Redis and your NodeJS apps (use the priority parameter to start Redis before your apps). Supervisord will automatically restart your NodeJS app if they crash.
You can then setup monit over it to be alerted when something wrong happens and to restart your NodeJS processes if they use too much memory/cpu or if they are not accessible anymore from a specific port.

Resources