Unit: NodeJS app as only worker?!

Created on 25 Mar 2019  路  9Comments  路  Source: nginx/unit

Is it possible to create an app with nodejs without using http server? Let's say i need some kind of background worker which will run and scan some directory for new files and process them. Or is Unit only intended to be a http/web server?!

Thanks!

question

All 9 comments

Unit starts applications to serve requests. Application process may have other background threads or sub-processes, but primary goal for Unit application is request processing.

Please provide more details why do you need Unit to start non-server processes.

Thanks in advance.

Like i've described before, NodeJS is not only used to serve requests, but also as an background worker. For example it could be used as some "parser/scraper" to get data from some kind of websites and to store those in database. Also it could be used to do some analytics in background too, also real "background worker".

So, for that work i will have to install "pm2" or other process management system. Which sense will it make to install "unit" to only process requests when with "pm2" i could achieve both, requests and background processing?

pm2 is a generic process management for Node.js, it doesn't handle connections. All the requests are served by Node.js instances in this case. Usually you need a reverse proxy (like nginx) in front for robustness and scalability.

Unit is more like an effective proxy and accelerator for Node.js (that comparing to nginx integrates more tightly and thus can do process management as well). It handles all the connections, parses requests and distributes work between Node.js processes using shared memory. It's robust and scales well. You can update your code, update Node.js without loosing connections, route requests between different Node.js applications and applications written in other languages. Besides that, it works the same way with other languages (Python, Ruby, PHP, Java, Perl, Go) and unifies your web-stack.

If you need more generic process manager based on Node.js, than pm2 is a good choice. If you are interested in handling web connections, than Unit is a good choice. With each release it gets more and more web server features.

I wonder if "unit" can also manage nodejs processes (applications in this case), why it should be bind to a listener? It would be much better/easier to build full stack of application (with for example one listener and 3-5 applications) with only Unit, without a need of pm2, because Unit can do the same as well...

As an workaround it would be probably to make a listener without exposing port or binding to local interface (127.0.0.1) and let it run as an background worker.

@jsieler In fact it shouldn't be bind to a listener. You can already add an application object to Unit configuration without any listener pointing to it. 馃檪

Hm... But the application itself (app.js) should have server instance running (http+createServer), right?

@jsieler right, this way it initialises a communication interface with Unit daemon.

Okay. Thanks for your reply! Have a nice day!

Is it on the roadmap of Unit? As it would be an obvious and very useful feature. In many app servers there are background worker proceses

Was this page helpful?
0 / 5 - 0 ratings