javascript - Mean.js Node.js background processes -


i've got mean.js app i'm writing , conceptually confused background processes.

i need have processes run continuously in background operate on mongodb database , stuff cleanup, email, tweets, etc.

i need lot of same functionality , libraries have in web app available these background procs.

what best way this? start brand new source base , treat these worker procs separate app? or create, say, daemon folder , fork background procs when start server.js grunt?

i think confusing myself , making more complicated should be. have looked @ node daemon , child_processes , simple_daemon. i'm not sure path take.

thanks help.

you can use setinterval() run scheduled or repeating tasks within mean.js app. because of way node.js works, long node running app, callback defined run in setinterval() or settimeout() run once loaded. means can keep background logic inside controllers/models or in adjacent file. can include background script, e.g. require()-ing main app.js file, or anywhere within controllers, models, etc.

e.g.

app.js:

require('tasks/dostuff'); require('express');  /* express/app stuff here */ 

tasks/dostuff.js:

require('mongoose'); require('some/other/stuff');  setinterval( function() {     console.log('interval happened'); }, 1000); 

this approach require design/architectural considerations. namely, tasks tied successful execution of node mean.js app. if mean.js app crashes/dies, tasks have died.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -