www/apps/book/app/learn/fundamentals/environment-variables/page.mdx
import { Table } from "docs-ui"
export const metadata = {
title: ${pageNumber} Environment Variables,
}
In this chapter, you'll learn how environment variables are loaded in Medusa.
The Medusa application loads and uses system environment variables.
For example, if you set the PORT environment variable to 8000, the Medusa application runs on that port instead of 9000.
In production, you should always use system environment variables that you set through your hosting provider.
During development, it's easier to set environment variables in a .env file in your repository.
Based on your NODE_ENV system environment variable, Medusa will try to load environment variables from the following .env files:
As of Medusa v2.5.0, NODE_ENV defaults to production when using medusa start. Otherwise, it defaults to development.
`.env` File
</Table.HeaderCell>
</Table.Row>
</Table.Header> <Table.Body> <Table.Row> <Table.Cell>
`NODE_ENV` = `development` or not set
</Table.Cell>
<Table.Cell>
`.env`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`NODE_ENV` = `production`
</Table.Cell>
<Table.Cell>
`.env.production`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`NODE_ENV` = `staging`
</Table.Cell>
<Table.Cell>
`.env.staging`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`NODE_ENV` = `test`
</Table.Cell>
<Table.Cell>
`.env.test`
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>loadEnvIn the medusa-config.ts file of your Medusa application, you'll find a loadEnv function used that accepts process.env.NODE_ENV as a first parameter.
This function is responsible for loading the correct .env file based on the value of process.env.NODE_ENV.
To ensure that the correct .env file is loaded as shown in the table above, only specify development, production, staging or test as the value of process.env.NODE_ENV or as the parameter of loadEnv.
Since the Medusa Admin is built on top of Vite, you prefix the environment variables you want to use in a widget or UI route with VITE_. Then, you can access or use them with the import.meta.env object.
Learn more in the Admin Environment Variables chapter.
You can further customize the Medusa application behavior using the following predefined environment variables. You can set the environment variables in your .env file or in your deployment platform.
You should opt for setting configurations in medusa-config.ts where possible. For a full list of Medusa configurations, refer to the Medusa Configurations chapter.
`ADMIN_AUTH_TYPE` ([v2.12.0+](https://github.com/medusajs/medusa/releases/tag/v2.12.0))
</Table.Cell>
<Table.Cell>
A string indicating the authentication method that the JS SDK instance uses in the Medusa Admin. Possible values are `session` and `jwt`. Learn more in the [JS SDK Authentication guide](!resources!/js-sdk/auth/overview).
</Table.Cell>
<Table.Cell>
`session`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`ADMIN_JWT_TOKEN_STORAGE_KEY` ([v2.12.0+](https://github.com/medusajs/medusa/releases/tag/v2.12.0))
</Table.Cell>
<Table.Cell>
A string indicating the key used to store the authentication JWT token in the browser's local storage. Only applicable if `ADMIN_AUTH_TYPE` is set to `jwt`.
</Table.Cell>
<Table.Cell>
`medusa_auth_token`
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>