I would like to replace, in my getStaticProps, getStaticPaths and API routes, all mongodb connection URI strings by environment variables
From :
const client = await MongoClient.connect(
'mongodb+srv://XXX:XXX@cluster0.uqztxfp.mongodb.net/meetups?retryWrites=true&w=majority'
)
To:
const client = await MongoClient.connect(`${process.env.MONGODB_URI}`)
With MONGODB_URI coded like that in .env.local
DB_USER='XXX'
DB_PASS='XXX'
MONGODB_URI='mongodb+srv://$DB_USER:$DB_PASS@cluster0.uqztxfp.mongodb.net/meetups?retryWrites=true&w=majority'
It perfectly works on getStaticProps and api routes, but not with getStaticPaths where variable is undefined...
All documentation I have read says that .env are accessible from server throught getStaticPaths as well as getStaticProps and api folder.
Notice that the app perfectly works with hard coded string
Thanks in advance