0

I have a server up and running in my digitaldomain droplet. in my server code, I have a function called userCount(); which simply returns the number fo connected users.

I do not want to console.log the number of users on my server, each time someone is connected. This just creates a mess. Instead, I would like to be able to run this command whenever I need to see the "current user count".

How can I make my server in a way that, I will also be able to input commands to it (from the console) whenever it's needed?

What is the best and/or most optimal way of doing this?

1 Answer 1

1

How about exporting the relevant function and execute it whenever you feel like it?

droplet.js

...
function userCount() {
    return 42;
}
...
module.exports = {
    userCount: userCount
}

Create a wrapper file:

wrapper.js

var connected = require('./droplet.js');
console.log(connected.userCount());

Execute that file from the command line:

> node wrapper

If you do not want to create an additional file, use the node interface:

> node
console.log(require('./droplet.js').userCount());
Sign up to request clarification or add additional context in comments.

2 Comments

That is not a bad solution! Thank you very much!
I will still wait a bit more for more answers (if there are any) - if not this is already a solution for me.

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.