Why is process.env.DATABASE undefined on macOS?

Viewed 192

I have a MERN application that runs fine on a Windows machine, but when trying to deploy it to a colleague's macOS machine we're getting the below error. Console logging process.env.DATABASE reveals it is undefined on the macOS machine. We tried setting the variable by running export NODE_ENV=development in the console but still get the same error.

index.js

const express = require('express');
const session = require('express-session');
const mongoose = require('mongoose');
const MongoStore = require('connect-mongo');

const db = require('./database');
const router = require('./routes');

const app = express();

require('dotenv').config({ path: 'variables.env' });

app.use(session({
  secret: process.env.SECRET,
  key: process.env.KEY,
  resave: false,
  saveUninitialized: false,
  store: new MongoStore({ mongoUrl: process.env.DATABASE })
}));

app.use('/api', router);

app.set('port', process.env.PORT || 8000);

const server = app.listen(app.get('port'), () => {
  console.log(`Express running on port ${server.address().port}`);
});

variables.env

NODE_ENV=development
DATABASE=database path

error in console:

> server@1.0.0 start
> node ./index.js
Assertion failed: You must provide either mongoUrl|clientPromise|client in options
/Users/user/Documents/ATT-main/server/node_modules/connect-mongo/build/main/lib/MongoStore.js:119
            throw new Error('Cannot init client. Please provide correct options');
            ^
Error: Cannot init client. Please provide correct options
    at new MongoStore (/Users/user/Documents/ATT-main/server/node_modules/connect-mongo/build/main/lib/MongoStore.js:119:19)
    at Object.<anonymous> (/Users/user/Documents/ATT-main/server/index.js:32:10)

What am I missing?

0 Answers
Related