Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moxy/next-runtime-env

Package Overview
Dependencies
Maintainers
20
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moxy/next-runtime-env

NextJS plugin to pass environment variables to NextJS's runtime configuration

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
20
Created
Source

next-runtime-env

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

NextJS plugin to pass environment variables to NextJS's runtime configuration.

By default, NextJS does not make available process.env to the client side. The available solution for this problem is to set a runtime config in next.config.js to pass values which will be available in either server and client or just server.

The way to do it is by passing values to the publicRuntimeConfig and serverRuntimeConfig properties of the NextJS' config.

This plugin does that automatically for all environment variables starting with a certain prefix.

Installation

$ npm i --save-dev @moxy/next-runtime-env

Usage

// next.config.js
const withRuntimeEnv = require('@moxy/next-runtime-env');

module.exports = withRuntimeEnv({ ...options })({ ...nextConfig });

Multiple configurations can be combined together with function composition. For example:

// next.config.js
const withCSS = require('@zeit/next-css');
const withRuntimeEnv = require('@moxy/next-runtime-env');

module.exports = withCSS(
    withRuntimeEnv({
        removePrefixes: true,
    })({
        cssModules: true, // this options will be passed to withCSS plugin through nextConfig
    }),
);

API

OptionDescriptionTypeDefault
publicPrefixPrefix of variables to lookup and then pass to publicRuntimeConfigStringPUBLIC_
serverPrefixPrefix of variables to lookup and then pass to serverRuntimeConfigStringSERVER_
removePrefixesOption to remove prefix when passing variables to runtime configBooleanfalse

Tests

Any parameter passed to the test command, is passed down to Jest.

$ npm t
$ npm t -- --coverage # to generate coverage report
$ npm t -- --watch # during development

License

Released under the MIT License.

Keywords

FAQs

Package last updated on 27 Aug 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc