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

@daopk/env

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@daopk/env

dotenv + envalid

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27
decreased by-3.57%
Maintainers
1
Weekly downloads
 
Created
Source

@daopk/env

npm-image

This package provides a convenient way to enable type-safety for environment variables in your Node.js application by wrapping the functionality of dotenv and envalid libraries.

Installation

You can install this package using npm:

npm install @daopk/env

Usage

To use this package, create a file named env.ts in your source root folder and define your environment variables with their expected types using defineEnv function. For example:

import { defineEnv, num, str } from '@daopk/env';

export const env = defineEnv({
    NODE_ENV: str(),

    SERVER_HOST: str({ default: 'localhost' }),
    SERVER_PORT: num({ default: 3000 }),
});

After defining your environment variables, you can import the exported env variable from the env.ts file.

import { env } from '~/env';

console.log(env.NODE_ENV); // Prints the value of NODE_ENV as a string
console.log(env.SERVER_HOST); // Prints the value of SERVER_HOST as a string
console.log(env.SERVER_PORT); // Prints the value of SERVER_PORT as a number

To use the ~ alias in your TypeScript project, you need to configure the paths option in the tsconfig.json file. For example:

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "~/*": ["./src/*"]
    }
  }
}

Keywords

FAQs

Package last updated on 14 Jan 2024

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