I’m tring to deploy node js application , for that I’m using cpanel , I’m facing a problem in storing and fetching data from the database and also the email verification function is not sending the email, i figured out that the problem is in the enviroment variables which data like mongo connection string and email address are stored in it.when i put the values directly in the code it works just fine.
this is part of the index.js file :
const express = require('express')
const app = express()
const router = require('./router/router')
const cors = require('cors')
const mongoose = require('mongoose')
const dotenv = require('dotenv')
dotenv.config()
const port = process.env.PORT ||
const mongoUri = process.env.MONGO_PROD_URL
mongoose.connect(mongoUri, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('connected to mongodb')
}).catch((err) => {
console.log(err)
})
first i thought that the variables are not identified as string so i tried to put them in template literals like this
const mongoUri = `${process.env.MONGO_PROD_URL}`
but nothing changed
abdo elbahloul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2