R
Railway3d ago
Marko

Creating .env file on deploy

Hi! Is it possible to create .env file instead of using system environment variables from the UI?
15 Replies
Percy
Percy3d ago
Project ID: aba163f0-3827-4fcb-8b18-23cc52b79543
Marko
MarkoOP3d ago
aba163f0-3827-4fcb-8b18-23cc52b79543
Brody
Brody3d ago
may I ask the usecase?
Marko
MarkoOP3d 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
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
Configuring: Environment Variables | Next.js
Learn to add and access environment variables in your Next.js application.
Brody
Brody3d ago
I assure you next does not only use .env files
Marko
MarkoOP3d 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
Brody
Brody3d ago
are you using a Dockerfile?
Marko
MarkoOP3d ago
medusa is built on top of next no i'm not using docker
Brody
Brody3d ago
then I would recommend fixing your project configurations so that you are not limiting yourself to .env files
Marko
MarkoOP3d 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",
},
},
});
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",
},
},
});
but its not there ok thanks
Brody
Brody3d ago
are you using turbo?
Marko
MarkoOP3d ago
No just yarn
"setup-db": "cd ./apps/backend && npx medusa db:create --no-interactive && npx medusa db:migrate",
"setup-db": "cd ./apps/backend && npx medusa db:create --no-interactive && npx medusa db:migrate",
yarn run setup-db
Brody
Brody3d ago
have you deployed the changes after adding the variable to your Railway service
Marko
MarkoOP3d 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
Brody
Brody3d ago
try using service variables please
Want results from more Discord servers?
Add your server