# application-services

> Out of the box application environment and configuration service.

Latest version **9.2.0** (published 2026-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install application-services
pnpm add application-services
yarn add application-services
bun add application-services
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 9.2.0 |
| Published | 2026-08-24 |
| First published | 2023-01-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=24.14.0 |
| Dependencies | 5 |
| Unpacked size | 148.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nicolas Froidure |
| Maintainers | nfroidure |
| Keywords | env, config, knifecycle |

## Links

- npm: https://www.npmjs.com/package/application-services
- Repository: https://github.com/nfroidure/application-services
- Homepage: https://github.com/nfroidure/application-services#readme
- Issues: https://github.com/nfroidure/application-services/issues
- Funding: https://github.com/sponsors/nfroidure
- npm.io page: https://npm.io/package/application-services

## Dependencies (5)

- [dotenv](https://npm.io/package/dotenv.md) ^17.4.2
- [yerror](https://npm.io/package/yerror.md) ^11.0.0
- [knifecycle](https://npm.io/package/knifecycle.md) ^21.4.0
- [common-services](https://npm.io/package/common-services.md) ^20.1.0
- [package-directory](https://npm.io/package/package-directory.md) ^8.2.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 9.2.0 (latest) — 2026-08-24
- 9.1.0 — 2026-08-22
- 9.0.1 — 2026-04-17
- 9.0.0 — 2026-04-07
- 8.0.1 — 2026-03-27
- 8.0.0 — 2026-03-26
- 7.0.4 — 2025-11-06
- 7.0.3 — 2025-07-11
- 7.0.2 — 2025-02-06
- 7.0.1 — 2024-12-06
- 7.0.0 — 2024-12-04
- 6.1.0 — 2024-07-15
- 6.0.0 — 2024-02-27
- 5.0.1 — 2024-02-24
- 5.0.0 — 2024-02-20
- … 6 more at https://npm.io/package/application-services/versions

## README

[//]: # ( )
[//]: # (This file is automatically generated by a `metapak`)
[//]: # (module. Do not change it  except between the)
[//]: # (`content:start/end` flags, your changes would)
[//]: # (be overridden.)
[//]: # ( )
# application-services
> Out of the box application environment and configuration service.

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/application-services/blob/main/LICENSE)
[![Coverage Status](https://coveralls.io/repos/github/nfroidure/application-services/badge.svg?branch=main)](https://coveralls.io/github/nfroidure/application-services?branch=main)


[//]: # (::contents:start)

Need to manage several environment and configurations for your
[`knifecycle`](https://github.com/nfroidure/knifecycle) based app? This module
is all what your need.

## Features

Out of the box, standard compliant, application environment:

- accepting only
  [standard](https://koistya.medium.com/demystifying-node-env-var-b25ed43c9af)
  `NODE_ENV` values: `test`, `development`, `production`,
- managing application environment in a clean and separate `APP_ENV` environment
  variable,
- leverage `dotenv` to read environment variables,
- use secret files to fill environment variables (useful for
  [Docker Compose secrets](https://docs.docker.com/compose/how-tos/use-secrets/)),
- manage separate and type checked applications configurations for each
  deployment environments and allows loading it automatically (in the
  `./configs/${APP_ENV}/index` file).

It requires `log` and `importer` services to be passed in, you can find
implementations in the
[`common-services`](https://github.com/nfroidure/common-services) project.

It also relies on constant services you will have to provide: `APP_ENV`,
`NODE_ENV` and the `MAIN_FILE_URL` (directory where actual code is).

[//]: # (::contents:end)

# API
## Constants

<dl>
<dt><a href="#PROCESS_ENV
Provides the PROCESS_ENV service">PROCESS_ENV
Provides the PROCESS_ENV service</a> : <code>Object</code></dt>
<dd></dd>
</dl>

## Functions

<dl>
<dt><a href="#extractAppEnv">extractAppEnv(appEnv, availableAppEnvs)</a> ⇒</dt>
<dd><p>Cast any string into an application environment</p>
</dd>
<dt><a href="#initAppConfig">initAppConfig(services)</a> ⇒ <code>Promise.&lt;Object&gt;</code></dt>
<dd><p>Initialize the APP_CONFIG service according to the APP_ENV</p>
</dd>
<dt><a href="#initENV">initENV(services)</a> ⇒ <code>Promise.&lt;Object&gt;</code></dt>
<dd><p>Initialize the ENV service using process env plus dotenv files
 loaded in <code>.env.node.${ENV.NODE_ENV}</code> and <code>.env.app.${APP_ENV}</code>.</p>
</dd>
<dt><a href="#readSecretFile">readSecretFile()</a></dt>
<dd><p>Extracts a secret from a file. Useful if you prefer
 extracting your secrets yourself considering the
 ENV service as unsafe.</p>
</dd>
<dt><a href="#initProcess">initProcess(services)</a> ⇒ <code>Promise.&lt;Object&gt;</code></dt>
<dd><p>Instantiate the process service</p>
</dd>
<dt><a href="#initProjectDirectory">initProjectDirectory(services)</a> ⇒ <code>Promise.&lt;Object&gt;</code></dt>
<dd><p>Initialize the PROJECT_DIR service</p>
</dd>
<dt><a href="#initTimeMock">initTimeMock(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
<dd><p>Instantiate the time mock service</p>
</dd>
</dl>

<a name="PROCESS_ENV
Provides the PROCESS_ENV service"></a>

## PROCESS\_ENV
Provides the PROCESS\_ENV service : <code>Object</code>
**Kind**: global constant  
<a name="extractAppEnv"></a>

## extractAppEnv(appEnv, availableAppEnvs) ⇒
Cast any string into an application environment

**Kind**: global function  
**Returns**: string  

| Param | Description |
| --- | --- |
| appEnv | string |
| availableAppEnvs | string[] |

<a name="initAppConfig"></a>

## initAppConfig(services) ⇒ <code>Promise.&lt;Object&gt;</code>
Initialize the APP_CONFIG service according to the APP_ENV

**Kind**: global function  
**Returns**: <code>Promise.&lt;Object&gt;</code> - A promise of a an object the actual configuration properties.  

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | <code>Object</code> |  | The services `APP_CONFIG` depends on |
| services.APP_ENV | <code>Object</code> |  | The injected `APP_ENV` value |
| services.MAIN_FILE_URL | <code>String</code> |  | An URL pointing to the main file run |
| services.importer | <code>Object</code> |  | A service allowing to dynamically import ES modules |
| [services.log] | <code>Object</code> | <code>noop</code> | An optional logging service |

<a name="initENV"></a>

## initENV(services) ⇒ <code>Promise.&lt;Object&gt;</code>
Initialize the ENV service using process env plus dotenv files
 loaded in `.env.node.${ENV.NODE_ENV}` and `.env.app.${APP_ENV}`.

**Kind**: global function  
**Returns**: <code>Promise.&lt;Object&gt;</code> - A promise of an object containing the actual env vars.  

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | <code>Object</code> |  | The services `ENV` depends on |
| [services.BASE_ENV] | <code>Object</code> |  | Base env vars that will be added to the environment |
| [services.ENV_SECRETS_FILES] | <code>Object</code> |  | Options allowing to detect env vars to load in secret files |
| services.APP_ENV | <code>Object</code> |  | The injected `APP_ENV` value |
| services.PROCESS_ENV | <code>Object</code> |  | The injected `process.env` value |
| services.PROJECT_DIR | <code>Object</code> |  | The NodeJS project directory |
| [services.log] | <code>Object</code> | <code>noop</code> | An optional logging service |

<a name="readSecretFile"></a>

## readSecretFile()
Extracts a secret from a file. Useful if you prefer
 extracting your secrets yourself considering the
 ENV service as unsafe.

**Kind**: global function  
<a name="initProcess"></a>

## initProcess(services) ⇒ <code>Promise.&lt;Object&gt;</code>
Instantiate the process service

**Kind**: global function  
**Returns**: <code>Promise.&lt;Object&gt;</code> - A promise of the process object  

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | <code>Object</code> |  | The services `process` depends on |
| services.APP_ENV | <code>Object</code> |  | The injected `APP_ENV` value |
| [services.PROCESS_NAME] | <code>Object</code> |  | The process name to display |
| [services.SIGNALS] | <code>Object</code> |  | The process signals that interrupt the process |
| [services.exit] | <code>Object</code> |  | A `process.exit` like function |
| services.$instance | <code>Object</code> |  | The Knifecycle instance |
| services.$fatalError | <code>Object</code> |  | The Knifecycle fatal error manager |
| [services.log] | <code>Object</code> | <code>noop</code> | An optional logging service |

<a name="initProjectDirectory"></a>

## initProjectDirectory(services) ⇒ <code>Promise.&lt;Object&gt;</code>
Initialize the PROJECT_DIR service

**Kind**: global function  
**Returns**: <code>Promise.&lt;Object&gt;</code> - A promise of a an object the actual configuration properties.  

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | <code>Object</code> |  | The services PROJECT_DIR depends on |
| [services.log] | <code>Object</code> | <code>noop</code> | An optional logging service |

<a name="initTimeMock"></a>

## initTimeMock(services) ⇒ <code>Promise.&lt;function()&gt;</code>
Instantiate the time mock service

**Kind**: global function  
**Returns**: <code>Promise.&lt;function()&gt;</code> - A promise of the time function  

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | <code>Object</code> |  | The services to inject |
| services.CLOCK_MOCK | <code>Object</code> |  | An object to store the time mock state |
| [services.time] | <code>Object</code> | <code>noop</code> | A time function |
| [services.log] | <code>Object</code> | <code>noop</code> | A logging function |

**Example**  
```js
import {
  DEFAULT_LOGGER,
  initLog,
} from 'common-services';
import {
  initTimeMock,
} from 'application-services';

const CLOCK_MOCK = {
  referenceTime: Date.now(),
  mockedTime: Date.parse('2012-12-20T20:20:20Z'),
  isFixed: false,
};
const log = await initLog({
  logger: DEFAULT_LOGGER,
});

const time = await initTimeMock({
  log,
});
```

# Authors
- [Nicolas Froidure](http://insertafter.com/en/index.html)

# License
[MIT](https://github.com/nfroidure/application-services/blob/main/LICENSE)

---
_Source: https://npm.io/package/application-services · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
