LoginSignup
0
0

More than 3 years have passed since last update.

dotenvで環境変数ではなく .env 使う | Node.js

Posted at
$ npm install dotenv --save

プロジェクトのルートディレクトリに .env ファイルを作成します。


# これはコメント行
KEY1=VALUE1
KEY2=VALUE2

実装


require('dotenv').config();

if (typeof process.env.KEY1 == 'undefined') {
  console.error('Error: "KEY1" is not set.');
  process.exit(1);
}

console.log(process.env.KEY1);  //=> VALUE1
0
0
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
0