I'd like to load some environment variables into functions within my libs, and then be able to re-export this to several different Nextjs applications. i.e.
Within libs/api
export const getDatabaseConnection = () => {
const host = process.env.DB_HOST
const username = process.env.DB_USERNAME
...
return newDatabaseConnection
}
Within apps/myNextJSApp:
import { getDatabaseConnection } from '@myProject/api'
...
const databaseConnection = getDatabaseConnection()
...
When I run nx run myNextJSApp:serve
it's unable to pull the environment variables from the .env within the root directory, however if I run nx run api:test
it's completely happy. I think I could pull the environment variables from each app individually, and then pass them as params into my library functions, but this seems kind of tedious, and I was hoping theres a blanket solution to this where I could build my library modules with the environment variables, and export them to my NextJS apps.