Typesafe Env
Learn how to use the typesafe env variables in shipit
Shipit uses a typesafe environment variable system that allows you to define the environment variables that your application needs, making sure that you have all the required variables and that they are of the correct type.
It uses Zod library to define the schema of the environment variables.
You can find the environment variables definition in the src/env.ts
file that will look like this:
Adding a server environment variable
Server environment variables are the ones that are not exposed to the client, like API keys, database credentials, etc.
To add one, just add a new key to the server
object with the name of the variable and the type that it should be.
Adding a client environment variable
Client environment variables are the ones that are exposed to the client, like the Stripe publishable key, Crisp website ID, etc.
To add one, just add a new key to the client
object with the name of the variable prefixed with NEXT_PUBLIC_
.
You will also need to destructure it on the experimental__runtimeEnv
object.
For example, if you want to add a new variable called MY_CLIENT_VARIABLE
, you should add it like this: