0

I have an process which is running on my server in the background. The object is exported like this

module.exports = new Application()

because I only want one instance of the object to ever exist.

I then have a separate process which tries to call a prototyped function process of Application. It looks something like this

var app = require('./Application.js');

app.process(process.argv[2]);

and say the file is called process.js. I'll then call node process.js thing_to_pass

The trouble is, every time I do this is it re-instantiates application which leads to behavior I am not looking for.

How can I get around this? I was thinking of using socket.io to communicate between the two processes but this seems hackish.

3 Answers 3

3

You aren't going to be able to go down the road you are trying to go down. Because you have two different processes, you are going to make two different instances of Application. Sending messages from one process to another via socket.io isn't that hackish imo, definitely something to consider.

You could also consider using child_process and sending messages with kill http://nodejs.org/api/process.html

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

2 Comments

Why is it declaring a new instance of application? why isn't it just pulling in the one that already exists?
Because you are using two different processes, they are completely independent.
0

If you're using Linux, I would suggest to use UNIX-domain sockets.

Comments

0

If you want a running process to receive new data, it has to listen for that data in some way. Whether you set up an HTTP server and accept and process requests with new data, or socket.io, or you wait for info from the command line, watch a file for changes, or what have you.

If you start up a whole separate process, it will be logically segregated in every way from the currently running process, and thank goodness or else completely separate apps could mess with each other in unintended ways.

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.