# Deploying to Production

Deploying a Nodewood project to a production server is relatively easy, if you are comfortable with the JavaScript ecosystem. There are a couple unique steps, designed to save you time in the long run, but the rest will be familiar to you if you have deployed a JavaScript application to production before.

Deployment methods:


Other deploy methods will be added as Nodewood development proceeds.

# Manual Deployment

Sometimes, you just have to get in there and build your own deployment system. You may be restricted to certain hosts or systems that prevent you from using other methods, or you may just want to know intimately the details of how your application runs. These instructions are for you.

# Server Preparation

Before you begin deploying your application, you will need to ensure your server has certain applications and libraries installed:

  • PostgreSQL (opens new window): You will either need to install this yourself or used a hosted installation from your hosting provider. The latter is recommended, since properly administering a database server with respect to performance and security is a topic unto itself.
  • Node (opens new window): Fairly obviously, you will need to ensure that Node is installed. Version 14 (LTS) is recommended.
  • Yarn (opens new window): Yarn is used to install packages and run Nodewood.
  • Nginx (opens new window): This is the web server that will take requests and redirect them to your application.

Next, you will need to ensure certain JavaScript packages are globally installed:


You can install these packages with a single command: yarn global add pm2 knex @nodewood/cli.

# First-Time Deployment

The first time you deploy your code will have a few extra steps, compared to subsequent deployments.

  1. Install your code. I find that it's simplest to use git to checkout your code, and then you can just run git pull when you need to do updates. For bonus points, you can generate and use an RSA key to checkout your code, so you don't need to enter your password every time you check out your code in the future.
  2. Add your production .env file. This will be very similar to your development .env file, and placed in the same location. The main difference is that you will want to replace any development keys and settings for production settings.
  3. Add your production knexfile.js file. This is the file that tells Knex how to connect to your database. Again, simply replace with your production settings, which you should be able to copy from your .env file.
  4. Copy your .nodewood.js file.
  5. Install your node modules with yarn install from the project root.
  6. Run your database migrations with yarn migrate from the project root.
  7. Run your Stripe migrations with nodewood stripe:sync from the project root. Make sure you have production Stripe keys set in your .env file.
  8. Build your UI with NODE_ENV=production yarn build-ui from the project root.
  9. Start the API service using PM2 with pm2 start app/api/api.js.
  10. Save the PM2 configuration with pm2 save.
  11. Ensure PM2 starts with your configuration at system startup with pm2 startup.
  12. Purchase/generate SSL certificates and install them. You can either purchase certificates good for a year or more from various vendors, or use Let's Encrypt (opens new window) to generate free SSL certificates. If you go the Let's Encrypt route, you will likely want to set up their auto-renewing certificate bot, as their certificates only last on the order of months, for increased security.
  13. Configure Nginx to redirect web traffic to your app. (Examine wood/nginx-default.conf for reference.)

# Subsequent Deployments

Every subsequent deployment will be simpler, with just the following steps:

  1. Update your code. (This is where it helps to have used git before, since you can just run git pull.)
  2. Install any new node modules with yarn install from the project root.
  3. Run your database migrations with yarn migrate from the project root.
  4. Run your stripe migrations with nodewood stripe:sync from the project root.
  5. Rebuild your UI with NODE_ENV=production yarn build-ui from the project root.
  6. Restart your API with pm2 restart api.