Stefan Zeuch
Stefan Zeuch

Reputation: 141

Express JS - Using server side JS check if app is running on localhost

I am needing to check if my node js app using ExpressJS is running on my localhost (Development env.) and not on the live server and execute certain code if so. This has to be done server side. Any ideas how to check this?

Upvotes: 3

Views: 3129

Answers (1)

Littlebobbydroptables
Littlebobbydroptables

Reputation: 3731

Pass process.env variable to your node.js instance like this (for example)

node -e 'process.env.NODE_ENV = "development"'

and then just use

if(process.env.NODE_ENV === 'development') {
    ...
}

Upvotes: 7

Related Questions