Determine if running on Windows or Linux?


#1

How can I tell (on the server) if I’m running in Windows or Linux.

I’m developing in WIndows but then deploying to Modulus, and need to set some paths differently during testing/development.

thanks
Russell


#2

You could try this package: https://atmospherejs.com/mrt/platform.js


#3

process.platform is probably the easiest.

https://devdocs.io/node/process#process_process_platform

If you dig into the node internals, you can also use os

var platform = os.platform();
if (platform === 'freebsd' || platform === 'linux') {
  console.log("You are running linux!");
} else if (platform === 'win32') {
  console.log("You are running windows, bummer");
}

EDIT: of course this will only work on the server.


#4

Thanks, I got it working using the package suggested by Rob.