Production Mode


#1

Is there a documented way to switch into production mode with vapid in a self hosted environment? I’ve got everything working great on a DigitalOcean droplet, but can’t figure out how to switch to a production deployment.


#2

@cmall If you set an ENV variable for NODE_ENV=production, Vapid should flip on a few production features, including caching and non-dev error pages.


#3

Gave that a try in .env but the site seems to still run in dev mode (“Starting the development server”) with livereload active as well.


#4

@cmall What version of Vapid are you running? It sounds like a bug that existed pre v0.2.2.


#5

I’m on a recently installed 0.2.2

Not a node expert, so perhaps I’m doing something wrong, but I get the same thing locally and on my DO droplet.


#6

Bummer. What happens if you run NODE_ENV=production vapid start locally?


#7

Thanks, that worked, and has got me on the path to fixing this. I was using PM2 to manage the node processes. It didn’t seem to be picking up the .env vars. Passing “–env production” to PM2 when adding the app seems to work though.


#8

Nice.

I don’t know if you have any interest, but if you decide to write up a blog post on how you got things running on DigitalOcean, I’d love to link to it, so others can benefit from your trials.


#9

Had already planned on that. Will do. Really like Vapid so far!


#10

@cmall have you tries setting the environmental variables inside of an ecosystem.config.js in the root? That file is PM2s config file, I seemed to have to PM2 to work placing my ‘NODE_ENV=production’ in there
https://pm2.io/doc/en/runtime/guide/ecosystem-file/?utm_source=pm2&utm_medium=website&utm_campaign=rebranding


#11

That’s sort of what I did. PM2 can accept a .json as an argument, so I created a .json file with the following:

{
  "apps": [
    {
      "name": "MY_APP",
      "script": "npm",
      "args": "start",
      "env": {
        "NODE_ENV": "production",
        "PORT": "3000",
      }
    },
  ]
}

I think this is the same as what would be in the ecosystem.config.js file, though that can contain multiple apps (useful). Anyway, this worked, and seemed to be a more consistent way of getting the ENV variables injected.

I’m writing up a post about how I got it all working. Things seem really solid so far.


#12

Hi Scott, I put up a post documenting my DigitalOcean set up.

https://mallinson.ca/posts/12/vapid-on-digital-ocean

I’ll be expanding it a bit when I get it hooked up to production level database, and add some tips on moving a local site to the server. Excited about using Vapid for some more projects. I like the direction it’s going, and I hope to have some time to contribute.


#13

Nice!!! And doubly so that the site/post was made using Vapid. :clap:

Thanks so much for putting this together. I’ll add it to the Wiki now.