0
1

More than 3 years have passed since last update.

【Node.js】dotenvで環境変数設定

Last updated at Posted at 2021-05-17



Node.jsの環境変数について、同じような記事はたくさんあるけど、いつも忘れるので自分用メモを兼ねて。

dotenvをインストール

npm install --save dotenv


コード

たとえば、あるURLを環境変数にする場合

以下のように、.envファイルを作成する。
(ファイル名が、.envで、同じフォルダに保存する)

URL=https://www.abcdefg.com



すると、以下のように、process.envで呼び出せる。

hogehoge.js
require("dotenv").config();

const URL = process.env.URL



0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1