[SOLVED] How to secure .env information

Hello, I am trying to connect my app to moralis using express and I put my keys in a .env file in the same folder that I am using to connect and then at the top of my routes I have:

const router = require('express').Router();
const Moralis = require('moralis/node')
const { popularNFTs } = require('../src/collections')
const serverUrl = process.env.serverUrl
const appId = process.env.appId

then I call later

await Moralis.start({ serverUrl, appId });

My server crashes and I get the error โ€œWeb3Api.initialize failed: initialize with apiKey or serverUrlโ€

The app works perfectly if I hard code my .env variables, but obviously I donโ€™t want to do that.

Hi make sure your .env file is in the root folder of your project. Also test that you can just console log your environment variables directly.

1 Like

Thank you! that worked perfectly

1 Like