How to import data from a .env file in TypeScript project? #3583
Answered
by
lobunto
liberatingsayan
asked this question in
Sanity Studio Support
-
I want to build sanity studio (sanity.io), in the studio root folder, there is a file, that is
I want to import the projectId & dataset from a
Please help me! |
Beta Was this translation helpful? Give feedback.
Answered by
lobunto
Sep 2, 2022
Replies: 2 comments 1 reply
-
You can use dotenv to read Then you can do: import {createConfig} from 'sanity';
import {deskTool} from 'sanity/desk';
import {schemaTypes} from './schemas';
import { markdownSchema } from 'sanity-plugin-markdown';
import * as dotenv from 'dotenv'
dotenv.config()
export default createConfig({
name: 'default',
title: 'dev-portfolio',
projectId: process.env.SANITY_STUDIO_API_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_API_DATASET,
plugins: [deskTool(), markdownSchema()],
schema: {
types: schemaTypes,
},
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
export default createConfig({
projectId: import.meta.env.SANITY_STUDIO_API_PROJECT_ID
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
kmelve
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.env
file with the config.process.env.*
you will need to doimport.meta.env.*
to access the variables.