Can I detect if I'm running in local environment?

I’d like to be able to detect if I’m running in local dev environment (fdk run) so I can write some log messages only locally but not write those messages if deployed to the server.

For example, I have some log timing messages.

I push the logs thru a single “log()” function so it would be pretty easy to add a check in that location and defer the log message.

So for example, I have this:

var log=function() {
       console.log.apply(console, arguments)
var logTime=function() {
       not_local = <ENVIRONMENT IS NOT LOCAL>
       if ( not_local ) return()
	var args =;
	console.log("API Time (%s) %s", args[1], args[0])

I’m looking for the code to put in

if not a standard way to do this, could I possibly check the URL of the webhook? If “localhost”, then its local. right?

1 Like

Hey Steve

You can check if the environment is local by writing a method similar to this

For app.js

const isLocal = () => {
  const params = new URL(window.location.href).searchParams;
  return params.get('dev') === 'true';

For server.js

const isLocal = () => {
  // a work around
  return process.cwd().includes('/path/to/your/app');

hope this helps!


Thanks! This is a great solution.

1 Like