npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tramvai/module-environment

v6.82.13

Published

The env module is used to retrieve global application environment variables in runtime and pass these parameters to the client. With a pre-defined list of variables used by the application, dynamically extended and validated at application startup

Readme

Env

The env module is used to retrieve global application environment variables in runtime and pass these parameters to the client. With a pre-defined list of variables used by the application, dynamically extended and validated at application startup

Installation

Already supplied inside @tramvai/module-common and does not need to be installed if module-common is connected.

Otherwise, you need to install @tramvai/module-environment

Explanation

Dynamically generated list of used env variables

All the parameters used in the application are registered by implementing the ENV_USED_TOKEN token in the DI and it is assumed that each module individually registers only the env parameters it needs. In this case, when a module is connected, there will be automatic validation of all passed parameters that are necessary for the application to work

import { provide } from '@tramvai/core';

@Module({
  providers: [
    provide({
      provide: ENV_USED_TOKEN,
      useValue: [
        { key: 'DEBUG_MODULE' },
        { key: 'DEBUG_MODULE_URL' },
      ],
      multi: true,
    }),
  ],
})
export class MyModule {}

In the above example, the module registers several env tokens, which will be initialized and will be available in environmentManager.get('DEBUG_MODULE'). In doing so, the optional parameter has been passed, which indicates that the variables are not required for the application to work.

Validation of environment variables values

When the application starts, it checks the tokens that were registered in the DI and passed to env at startup. If all required env variables have not been passed to the application, the application will crash.

It is also possible to write validators for env values, which will run when the application is initialized.

import { provide } from '@tramvai/core';

@Module({
  providers: [
    provide({
      provide: ENV_USED_TOKEN,
      useValue: [
        {
          key: 'MY_ENV',
          validator: (env) => {
            if (!env.includes('https')) {
              return 'Incorrect link format. The link should contain https';
            }
          },
        },
      ],
      multi: true,
    }),
  ],
})
export class MyModule {}

Functionality works on the server and in the browser

All env variables will be available both on the server and in the browser without any additional actions or settings. Env variables that have dehydrate: true are automatically passed to the browser

Priority of obtaining values for env variables

Since it is possible to overwrite the values of the variables, the variables are replaced according to certain rules

The replacement rules are arranged in order of priority, from lower to higher:

  • Parameters set in tokens { key: 'ENV_PARAM', value: 'env value' }
  • Parameters written in env.development.js file
  • Passing application launch parameters MY_ENV=j node server.js

API

@inline ../../tokens/common/src/env.ts

How to

How to read data in an application

Suppose we registered the parameter CONFIG_API used by env with the ENV_USED_TOKEN token, now we need to connect environmentManager in the application and read the data:

import { provide } from '@tramvai/core';

@Module({
  providers: [
    provide({
      provide: 'MY_SERVICE',
      useClass: class MyService {
        constructor({ environmentManager }) {
          console.log(environmentManager.get('CONFIG_API'));
        }
      },
      deps: {
        environmentManager: ENV_MANAGER_TOKEN,
      },
    }),
  ],
})
export class MyModule {}

This code will work both on the server and in the browser

How you can simply pass parameters in local development

To do this, create a file env.development.js in the root of the project and write all env variables for the application. When the application is initialized, this file will be read.

Peculiarities of using env.developmen.js in production builds

The twelve factors application stores the configuration in environment variables, so by default when process.env.NODE_ENV === 'production' EnvironmentManger will not read the env.development.js file.

If you want to test the application locally with NODE_ENV=production, you can pass the flag DANGEROUS_UNSAFE_ENV_FILES='true' so that EnvironmentManger will read the env.development.js file and not have to enter all variables by hand.

How to pass env parameters to the application during the deploys

To do this, pass env parameters when starting the application. For example in Docker you can do this with the parameter -e docker run -e MY_ENV_VAR=/ my-image.

How to view all env variables of an application

This method allows you to see only client variables

To get a list of variables, there is a /papi/apiList method

Request example: http://localhost:3000/${appName}/papi/apiList

How to make an ENV variable optional?

To do this, pass optional: true parameter. For example { key: 'DEBUG_MODULE', optional: true }