Creating .env file on deploy
mk0y
HOBBYOP

a year ago

Hi!
Is it possible to create .env file instead of using system environment variables from the UI?

22 Replies

mk0y
HOBBYOP

a year ago

aba163f0-3827-4fcb-8b18-23cc52b79543


a year ago

may I ask the usecase?


mk0y
HOBBYOP

a year ago

In Next.js they use .env only https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
when i export it locally i'm getting

error:   Missing "DATABASE_URL" inside the .env file. The value is required to connect to the PostgreSQL server

It's irrelevant to Railway, but only asking if we can use .env files at Railway


a year ago

I assure you next does not only use .env files


mk0y
HOBBYOP

a year ago

It's actually medusajs, https://docs.medusajs.com/learn/advanced-development/environment-variables, but i'm getting that error, i'm sure i have it exported DATABASE_URL


a year ago

are you using a Dockerfile?


mk0y
HOBBYOP

a year ago

medusa is built on top of next


mk0y
HOBBYOP

a year ago

no i'm not using docker


a year ago

then I would recommend fixing your project configurations so that you are not limiting yourself to .env files


mk0y
HOBBYOP

a year ago

This is where they load envs

const { QUOTE_MODULE } = require("./src/modules/quote");
const { loadEnv, defineConfig, Modules } = require("@medusajs/framework/utils");

loadEnv(process.env.NODE_ENV, process.cwd());

module.exports = defineConfig({
  projectConfig: {
    databaseUrl: process.env.DATABASE_URL,
    http: {
      storeCors: process.env.STORE_CORS,
      adminCors: process.env.ADMIN_CORS,
      authCors: process.env.AUTH_CORS,
      jwtSecret: process.env.JWT_SECRET || "supersecret",
      cookieSecret: process.env.COOKIE_SECRET || "supersecret",
    },
  },
  modules: {
    companyModuleService: {
      resolve: "./modules/company",
    },
    [QUOTE_MODULE]: {
      resolve: "./modules/quote",
    },
    [Modules.CACHE]: {
      resolve: "@medusajs/medusa/cache-inmemory",
    },
    [Modules.WORKFLOW_ENGINE]: {
      resolve: "@medusajs/medusa/workflow-engine-inmemory",
    },
  },
});

mk0y
HOBBYOP

a year ago

but its not there


mk0y
HOBBYOP

a year ago

ok


mk0y
HOBBYOP

a year ago

thanks


a year ago

are you using turbo?


mk0y
HOBBYOP

a year ago

No just yarn


mk0y
HOBBYOP

a year ago

    "setup-db": "cd ./apps/backend && npx medusa db:create --no-interactive && npx medusa db:migrate",

yarn run setup-db


a year ago

have you deployed the changes after adding the variable to your Railway service


mk0y
HOBBYOP

a year ago

No i haven't, currently i'm looking if i can use .env file instead, because with env file envs load, using export they don't


a year ago

try using service variables please


francisco-vivas
FREE

6 months ago

I try use service variables in a MedusaJS project but the same error is still present — Missing "DATABASE_URL" inside the .env file. The value is required to connect to the PostgreSQL server


fra
HOBBYTop 10% Contributor

6 months ago

can you try skipping loadEnv(process.env.NODE_ENV, process.cwd()); it process.env.NODE_ENV===production ? and also can you double checkout you don't have any .env file in your repo?


fra

can you try skipping loadEnv(process.env.NODE_ENV, process.cwd()); it process.env.NODE_ENV===production ? and also can you double checkout you don't have any .env file in your repo?

venturero
FREE

4 months ago

then how can he add API keys? I want to create a project with OpenAI API keys.


Loading...