Search code examples
javascriptnode.jsweb-worker

Webworker vs node environment


How do I tell the difference between webworker and a node environment? Neither of them have a window. They appear similar as a result.


Solution

  •  if(module) console.log("node");
    

    As far as i know, web workers don't have modules. There are probably a lot of other globals that are only available in node, require for example, or __dirname , here is a complete list.