LoginSignup
9
2

More than 3 years have passed since last update.

Next.jsでenvファイルを使う

Posted at

やること

envファイルをNext.jsで使えるようにする。

必要パッケージインストール

dotenvをインストール

yarn add dotenv

.env作成

TEST = HOGEHOGE

next.config.js作成

next.config.js
require('dotenv').config()

module.exports = {
  env: {
    TEST: process.env.TEST,
  },
}

読み込む

pages/index.js
export default () => <p>process.env.TEST:{process.env.TEST}</p>

スクリーンショット 2019-12-17 23.40.53.png

おわり

Next.jsの記事が少ないと感じているので、ちょっとしたことでも投稿していこうと思った。

9
2
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
9
2