Search code examples
javascriptnode.jsserver-side

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?


Solution

  • 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') {
        ...
    }