Replace URL during build step of npm

Viewed 93

I've a mock REST service during development and a real backend I want to use for the public release. Is there a way to replace the endpoint URL somehow during the npm build step?

1 Answers

You can use process.env.NODE_ENV to measure whether it is at development environment or production environment.

It would be something like this:

const baseUrl = process.env.NODE_ENV === 'development' ? 'localhost:3000' : 'www.live.com'

localhost:3000 would be the backend url while you developing.

Related