Envars in JSON?

I need to use a variable in a PWA file, specifically process.env.PROJECTURL
However, I cant get it to work. It just parses it as process.env.PROJECTURL
Anyone know how I can parse .env variables in a .json file?

I’m a bit confused about what you are asking. Why not just parse the JSON file and get the values from there?

I was working on making a tutorial for the ansyble PAW, and I wanted to use that variable for it. However, the parser didn’t recognize it. I tested it.
I was asking how I could use .env variables in the manifest.json file.

What you can do is something similar to what’s suggested here. Here’s how I would go about it:

  1. First, if your project doesn’t already serve files using express, change it to do that - see hello-express
  2. change your manifest.json file to manifest.js, and use module.exports = {/*your json object*/}
  3. In your server file, add const manifest = require("./manifest.js"); to the top
  4. Do something like this:
app.get("/manifest", (req, res) => {
 res.json(manifest);
});
  1. Then in your client-side files make sure your manifest points to “/manifest”

Bear in mind I’ve got mo idea what this ansyble project is, so this might not work for your case.

Aeiou! This is for a PWA, and it wont work!

It will work, I make apps with PWAs and have used this method.

1 Like