mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
format
This commit is contained in:
@@ -11,7 +11,6 @@ Before you can set up a `.env` file with TypeScript in Node.js, you need to inst
|
||||
|
||||
`npm install dotenv @types/dotenv --save-dev`
|
||||
|
||||
|
||||
## Step 2: Create a .env File
|
||||
|
||||
1. Create a new file named `.env` in the root directory of your project.
|
||||
@@ -19,28 +18,26 @@ Before you can set up a `.env` file with TypeScript in Node.js, you need to inst
|
||||
|
||||
VAR_NAME=value
|
||||
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
DB_HOST=localhost
|
||||
DB_USER=admin
|
||||
DB_PASS=password123
|
||||
DB_HOST = localhost
|
||||
DB_USER = admin
|
||||
DB_PASS = password123
|
||||
```
|
||||
|
||||
|
||||
## Step 3: Load Environment Variables
|
||||
|
||||
1. In your TypeScript file, import the `dotenv` package:
|
||||
|
||||
```ts
|
||||
import dotenv from 'dotenv';
|
||||
import dotenv from 'dotenv'
|
||||
```
|
||||
|
||||
2. Call the config method of the dotenv package to load the environment variables from the .env file:
|
||||
|
||||
```ts
|
||||
dotenv.config();
|
||||
dotenv.config()
|
||||
```
|
||||
|
||||
## Step 4: Access Environment Variables
|
||||
@@ -48,9 +45,9 @@ dotenv.config();
|
||||
You can now access your environment variables using the process.env object. For example:
|
||||
|
||||
```ts
|
||||
const dbHost = process.env.DB_HOST;
|
||||
const dbUser = process.env.DB_USER;
|
||||
const dbPass = process.env.DB_PASS;
|
||||
const dbHost = process.env.DB_HOST
|
||||
const dbUser = process.env.DB_USER
|
||||
const dbPass = process.env.DB_PASS
|
||||
```
|
||||
|
||||
And that's it! You have now set up a .env file with TypeScript in Node.js and can access your environment variables in your code.
|
||||
|
||||
Reference in New Issue
Block a user