Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9060

nodeで.envを作る

$
0
0
node.jsで設定ファイルを一か所に集めたくなったので、 envファイルで設定値を保存したくなったので調べたら dotenvっていうパッケージを見つけたので、 使ってみた。 dotenvのページ  インストール npm install dotenv  .envファイルを作る プロジェクトルートに.envファイルを作る 中身はこんな感じ /.env hoge = hogehogehogehoesetting # 環境変数を定義コメントはこんな感じ fuga = 設定値 使う index.jsに以下を配置 require('dotenv').config(); 他のファイルでは、読み込む必要は無い 設定値の読みだし console.log(process.env.hoge) // hogehogehogehoesetting って感じで、設定している文字列を取得できる ちょう簡単

Viewing all articles
Browse latest Browse all 9060

Latest Images

Trending Articles