# @platform/npm.express

> Express middleware for working with NPM.

Latest version **0.1.169** (published 2021-08-31) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @platform/npm.express
pnpm add @platform/npm.express
yarn add @platform/npm.express
bun add @platform/npm.express
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.169 |
| Published | 2021-08-31 |
| First published | 2019-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 40.2 KB |
| Known vulnerabilities | 0 (+7 in 4 direct dependencies) |
| Install scripts | no |
| Maintainers | philcockfield |

## Links

- npm: https://www.npmjs.com/package/@platform/npm.express
- npm.io page: https://npm.io/package/@platform/npm.express

## Dependencies (8)

- [semver](https://npm.io/package/semver.md) 7.3.5
- [express](https://npm.io/package/express.md) 4.17.1
- [filesize](https://npm.io/package/filesize.md) 8.0.0
- [minimist](https://npm.io/package/minimist.md) 1.2.5
- [body-parser](https://npm.io/package/body-parser.md) 1.19.0
- [@platform/npm](https://npm.io/package/@platform/npm.md) 0.4.18
- [@platform/exec](https://npm.io/package/@platform/exec.md) 0.3.12
- [@types/express](https://npm.io/package/@types/express.md) 4.17.13

## Recent versions

- 0.1.169 (latest) — 2021-08-31
- 0.1.168 — 2021-08-31
- 0.1.167 — 2021-07-19
- 0.1.165 — 2021-07-19
- 0.1.159 — 2021-06-04
- 0.1.158 — 2021-05-29
- 0.1.157 — 2021-05-17
- 0.1.156 — 2021-05-17
- 0.1.155 — 2021-05-14
- 0.1.154 — 2021-05-13
- 0.1.153 — 2021-03-29
- 0.1.152 — 2021-03-29
- 0.1.151 — 2021-02-23
- 0.1.150 — 2021-02-19
- 0.1.149 — 2021-02-19
- … 94 more at https://npm.io/package/@platform/npm.express/versions

## README

![Module](https://img.shields.io/badge/%40platform-npm.express-%23EA4E7E.svg)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![NPM](https://img.shields.io/npm/v/@platform/npm.express.svg?colorB=blue&style=flat)](https://www.npmjs.com/package/@platform/npm.express)
![banner](https://user-images.githubusercontent.com/185555/56625096-bd12e780-668f-11e9-935e-58bea6081f51.png)

[Express](https://expressjs.com) [middleware](https://expressjs.com/en/guide/using-middleware.html) for working with [NPM](http://npmjs.com).

- Continuous deployment via [NPM](http://npmjs.com).
- Run as [middleware](https://expressjs.com/en/guide/using-middleware.html) or use [Docker container](https://www.docker.com) directly (recommended).

<p>&nbsp;<p>

<p>&nbsp;<p>

## Example

Run the example directly in node:

    yarn example

or run the example within docker:

    yarn dbuild
    cd examples
    docker-compose up

see the `/examples/docker-compose.yml` file for example configuration and command-line arguments to pass to the container.

<p>&nbsp;<p>

## Middleware

To use the [express middleware](https://expressjs.com/en/guide/using-middleware.html) directly

```typescript
import * as express from 'express';
import { router } from '@platform/npm.express';

const getContext = async () => {
  return {
    name: 'my-module',                // Name of the NPM module being managed.
    downloadDir: '/download/folder',  // Directory where latest NPM version is downloaded to.
  };
};

const routes = router.create({ getContext });
const server = express().use(routes);
server.listen(1234);
```

## Routes

    GET   /status
    POST  /update
    POST  /start
    POST  /stop

Query-string parameters for `/status`:
```typescript
{
  versions?=<number>    // Include version history. If number (n) provided returns only the latest (n) versions.
  size?=<boolean>       // Include size of the download folder.
}
```


Body parameters for `/update`:
```typescript
{ 
  restart?: boolean;                        // Restart the service once updated (default: true)
  version?: string | 'latest';              // Specific version to install (default: 'latest')
  prerelease?: boolean | 'alpha' | 'beta',  // Install pre-release version, eg 1.2.0-beta.0 (default: false)
  reset?: boolean,                          // Delete existing download before installing (default: false)
  dryRun?: boolean,                         // Perform all checks, but don't actually change anything.
}
```

Body parameters for `/start`:
```typescript
{ restart?: boolean }
```


## Command-Line Arguments

To configure the module when working with it as [Docker container](https://www.docker.com) pass the following command-line arguments:

```bash
    --npm-module='<string>'             # (required) The name of the NPM module being managed.
    --dir='<string>'                    # (required) Path to the download directory.
    --port='<number>'                   # (optional) Port to run the management server on.
    --prerelease='<boolean|alpha|beta>' # (optional) Whether pre-release versions should be used (default:false).
    --url-prefix='<string>'             # (optional) Prefix to prepend URL's with, eg /foo => GET /foo/status
    --update                            # (optional) Flag indicating if update performed at startup (default:false).
    --npm-token                         # (optional) An NPM authorization token if working with private modules.
```

see the `/examples/docker-compose.yml` file for example configuration.


### .env
These same arguments can alternatively be specified as environment variables, see `/example/env/main.env` and the `env_file` reference in `docker-compose.yml` for example.

```bash
NPM_MODULE=           --npm-module
NPM_DIR=              --dir
NPM_PORT=             --port
NPM_PRERELEASE=       --prerelease
NPM_URL_PREFIX=       --url-prefix
NPM_UPDATE=           --update
NPM_TOKEN=            --npm-token
```

Any values passed explicitly to the command will override the environment variables.


## Private NPM Packages

Follow the instructions on NPM ["Using private packages in a CI/CD workflow"](https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow) to create a token to access your private modules:

    npm token create --read-only

Alternatively tokens can be created within the [npmjs.com](https://www.npmjs.com) adminitration UI.  
Pass the token as either a command-line argument or an environment variable at startup.

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