Socket
Socket
Sign inDemoInstall

next-runtime-dotenv

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    next-runtime-dotenv

Expose environment variables to the runtime config of Next.js


Version published
Weekly downloads
1.2K
decreased by-41.32%
Maintainers
1
Install size
81.4 kB
Created
Weekly downloads
 

Readme

Source

next-runtime-dotenv

Expose environment variables to the runtime config of Next.js

npm version codecov XO code style

CI

Tests Release

Getting started

$ yarn add next-runtime-dotenv

This Next.js plugin uses dotenv to expose environment variables to the Next.js runtime configuration. It requires next@5.1.0.

Usage

This module exposes a function that allows to configure a Next.js plugin.

In your next.config.js:

const nextRuntimeDotenv = require('next-runtime-dotenv')

const withConfig = nextRuntimeDotenv({
  // path: '.env',
  public: [
    'MY_API_URL'
  ],
  server: [
    'GITHUB_TOKEN'
  ]
})

module.exports = withConfig({
  // Your Next.js config.
})

Then in your page, use the configuration values as such:

import getConfig from 'next/config'

const {
  publicRuntimeConfig: {MY_API_URL},  // Available both client and server side
  serverRuntimeConfig: {GITHUB_TOKEN} // Only available server side
} = getConfig()

function HomePage() {
  // Will display the variable on the server’s console
  // Will display undefined into the browser’s console
  console.log(GITHUB_TOKEN)

  return (
    <div>
      My API URL is {MY_API_URL}
    </div>
  )
}

export default HomePage

Serverless deployment

This module is not compatible with serverless deployment as publicRuntimeConfig and serverRuntimeConfig from next/config will not be exposed. You should use build-time configuration.

Phases

This plugin leverages next@5.1.0 and build phases. It exposes a plugin function in order to run the plugin only when running the server (PHASE_DEVELOPMENT_SERVER and PHASE_PRODUCTION_SERVER).

License

MIT

Miscellaneous

    ╚⊙ ⊙╝
  ╚═(███)═╝
 ╚═(███)═╝
╚═(███)═╝
 ╚═(███)═╝
  ╚═(███)═╝
   ╚═(███)═╝

Keywords

FAQs

Last updated on 09 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc