Deployment and Hosting
You've done it. You're ready to deploy your application to a production environment. The good news is that should be easy, here are some tips.
How Deployment Works
One of the ideas in the Twelve-Factor App is that your development and your production environment should be as close as possible. This is because it makes deployment easier! And Factor is built for this.
Running npx factor start
builds and serves your application locally, and that's the same thing you'll be doing in deployment.
Basically, if you're Factor app is looking good locally, there is a good chance you're ready to go to production.
As outlined in the Dotenv doc, The only difference will be the environmental configuration which is dictated by the variables in .env
.
Setting Environmental Variables
The main difference between your local and production servers will be defined by environmental variables. While in your local setup, you only need to add the values to .env
, sometimes it can be tricky (depending on your host.)
Reference your host's documentation to see how they recommend you add and configure environmental variables.
Deployment Process
Deploying to production typically follows one of these two workflows:
Build Locally and Upload
- Build production app locally -
npx factor build
- Upload built code (in
/dist
) to server - Verify dependencies on server
npm install
- Run server -
npx factor serve
Or...
Build On Server
- Commit or upload app to build environment or server
- It builds the production app (
npx factor build
) - Verify dependencies on server
npm install
- Run server -
npx factor serve