How can I execute some code only in production environment and not execute when in it is in localhost:3000 ?
Those are two different questions For the first, you can use something like:
if (process.env.NODE_ENV === 'production') { ... }
if (process.env.NODE_ENV === 'development') { ... }
Presumably that’s all you need but if you really want to check if you’re on localhost:300
, on the client only, you can of course use:
if (location.host === 'localhost:3000') { ... }
There’s also a location.hostname
and location.port
for the individual components.
2 Likes