I am developing an IDE that enables developers to develop express.js applications. So, developers can create new express applications. Since resource consumption is vital, I do not want to run each express app in a separate process; actually they are all running in the main process as node.js modules. Now the problem is I do not have any idea what codes developers will write, for example whether they use functions like setInterval or not. Let me explain a little bit more:
Suppose this is the main program:
'use strict'
const mainApp = require('express')();
require('./userModule.js')();
mainApp.delete('/', function(req, res){
/*
What should I do here to delete the user code?
*/
res.status(202).send('deleted');
});
mainApp.listen(8000, () => console.log('Example app listening on port 8000!'))
And this is the code written by user in userModule.js function:
'use strict'
module.exports = function(){
// code written by user will come below
setInterval(function(){
console.log('hello!!!');
}, 3000);
// code written by user will come above
}
I already know the following:
1- Delete the module cache as explained here. That does not help.
delete require.cache[require.resolve('./userModule.js')];
2- ClearInterval when the ID is unknown as explained here. I do not want to clear all intervals! Moreover, it only works for setInterval function, what about others?!!!
I am reaching a point that there is no option if the module is running in the main process. Am i right?