🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

remix-env

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remix-env

Easy way to use process.env in your Remix apps

latest
Source
npmnpm
Version
4.0.0
Version published
Weekly downloads
37
42.31%
Maintainers
1
Weekly downloads
 
Created
Source

remix-env

Easy way to use process.env in your Remix apps

Setup

  • Run npm install remix-env or yarn add remix-env
  • Add EnvProvider in entry.client.tsx and entry.server.tsx

entry.client.tsx

startTransition(() => {
  hydrateRoot(
    document,
    <StrictMode>
+     <EnvProvider>
        <RemixBrowser />
+     </EnvProvider>
    </StrictMode>
  );
});

entry.server.tsx

export default function handleRequest(
  request: Request,
  responseStatusCode: number,
  responseHeaders: Headers,
  remixContext: EntryContext
) {
  const markup = renderToString(
+   <EnvProvider>
      <RemixServer context={remixContext} url={request.url} />
+   </EnvProvider>
  );
}
  • Add InjectEnv in root.tsx

root.tsx

export function Root() {
  return (
    <html lang="en">
      <head>
        <Meta />
        <Links />
      </head>
      <body>
+       <InjectEnv />
        <Outlet />
        <Scripts />
      </body>
    </html>
  );
}

Usage

Now, You can use the getEnv to get your env

const env = getEnv()

// app/routes/_index.tsx
export default function IndexRoute() {
  return (
    <div>
      {env.PUBLIC_ENV_FOO}
    </div>
  );
}

Configuration

By default this library will inject all environment variables with prefix PUBLIC_ENV_ to the browser.

But you can customize it by provide the filter function at EnvProvider.

<EnvProvider filter={(key, value) => key.startsWith("PUBLIC_ENV_")}>
  ...
</EnvProvider>

Keywords

remix

FAQs

Package last updated on 23 Sep 2023

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