[Vuejs]-Nuxt JS env file

4👍

Here are the steps to get this working:

First install dotenv with npm i -D dotenv

Next, make sure you have a .env file that looks something like:

ENCRYPTION_KEY="put your key here"

Finally, add the following to the top of your nuxt.config.js:

require('dotenv').config();

A word of caution

Please be aware that this will actually build your client code with ENCRYPTION_KEY in the source, so anyone could read it. If that isn’t what you want, I’d recommend doing all of your encryption on the server.

Leave a comment