Using modules with nodejs separate from NR?

Probably yes but a simple way would be to use an env variable e.g....

process.env.WITHOUTNODERED

If you determine you are NOT in node-red, then you could set node.xxxx functions to proxy functions instead of littering your code with if(isNodeRed) node.log(X) else console.log(X)

More info on env vars...