i have a server.js file written in node.js
i can start the server with ... node server
or i can start it with ... mimosa watch -s
in the server.js file i want to do ...
if (this was started with mimosa) {
do something
} else {
do something else
}
how could i detect this? please no answers such as ... why do you want to do this?
currently i can only detect ...
var thisIsMimosa = false;
exports.startServer = function (config, callback) {
thisIsMimosa = true;
startServer("mimosa");
};
if (thisIsMimosa == false) {
startServer("node");
}
THE PROBLEM IS ... thisIsMimosa is not set in time and so the node startServer call is not made when "node server" is used to start the server.
If someone knows a variable which will differ in value if mimosa was used to start the server then I can rely on that instead.
Many thanks in advance.
The
mimosa-config.js
is a piece of node.js. It's not a.json
file. So, you could, at the top of that file, do something like this:Then in your
server.js
you can checkprocess.env.IS_MIMOSA
. Mimosa reads in your config file long before it ever runs your server, so that variable should be ready to use.