3

I'm writing a node app which consists of a producer that takes in rest calls and pops them as jobs onto a job queue. Then also a number of worker apps that will consume the messages from the queue and perform their long running tasks. The producer will probably run on a single server, the workers will run (using PM2 to keep them alive and manage the threads) on multiple servers.

I'm after some advise on how best to structure the app, as once deployed there will need to be two apps (producer and consumer) run up on at least one of the servers.

Would it be best to completely separate the components in the project into folders like so...

ProjectRoot
|
+--producer
|     +--bin
|     +--node_modules
|     |--app.js
|
+--consumer
|     +--bin
|     +--node_modules
|     |--app.js

Or can I still use some common components, for instance, bring the node_modules and maybe a common to the project root level? Like so...

ProjectRoot
|
+--node_modules
+--common
+--producer
|     +--bin
|     |--app.js
|
+--consumer
|     +--bin
|     |--app.js

I realise this question could be considered subjective/opinion based, but it's best practises I'm after really.

2
  • Have a look at kue this is a really nice job queue with a rest API and extremely easy to use. You still might want to build your own of course, but since it's built on node, you can get some inspiration there. Commented Apr 15, 2015 at 11:37
  • Hi, thanks for the comment, I am indeed already using Kue, it's very good Commented Apr 15, 2015 at 11:46

1 Answer 1

1

You definally should keep node_modules folder as single resource, in case if you got a lot common models, etc.

If you haven't started designing structure yet, I would recommend use sails as main framework. You can create controllers, models, config in project folder. Then create another directory "worker" and simply import sails again. Once Sails app is lifted, you will have your models,services available automatically, see here, for example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.