Closed deduced closed 6 years ago
@fredricklou523 these articles are good primers on env variables: https://www.twilio.com/blog/2017/08/working-with-environment-variables-in-node-js.html and https://medium.freecodecamp.org/heres-how-you-can-actually-use-node-environment-variables-8fdf98f53a0a.
The TL;DR is that heroku automatically runs your application setting NODE_ENV to "production" by default which is what we want and the reason that you see the express server have the conditional wrapper for NODE_ENV !== 'production'. I added some scripts to facilitate local development and for production (heroku by default uses npm start
). Other than that, the articles I posted teach you about environment variables and how to use them (using dotenv package for example).
Hope that helps.
Also made some changes:
start
npm script runs parcel production build and node for productiondev
script runs both parcel build/watch and nodemon server at the same time/api
as a best practice (avoids problems with react endpoints stepping on any server static serving