Is there a way to determine when you are in the simulator or on device programmatically?

Viewed 64

I am looking for a way to differentiate between the device and the simulator programmatically for Vodapay mini-programs, does anyone know of a way to do this?

Thank you

1 Answers

You can make use of process.env.NODE_ENV to achieve this. It returns 'development' when in the simulator and 'production' when on device.

if (process.env.NODE_ENV ==='development') {
  //run this in simulator
  console.log('simulator');
}
else{
  // run this on device
  console.log('device');
}
Related