# @webruntime/server

> Lightning Web Runtime - Server

Latest version **1.61.4** (published 2021-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @webruntime/server
pnpm add @webruntime/server
yarn add @webruntime/server
bun add @webruntime/server
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.61.4 |
| Published | 2021-07-23 |
| First published | 2020-01-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 15 |
| Unpacked size | 393.6 KB |
| Known vulnerabilities | 0 (+11 in 5 direct dependencies) |
| Install scripts | no |
| Maintainers | tconn, diervo, zhawtof, kjkimsfdc, lwc-admin |

## Links

- npm: https://www.npmjs.com/package/@webruntime/server
- npm.io page: https://npm.io/package/@webruntime/server

## Dependencies (15)

- [hasha](https://npm.io/package/hasha.md) 5.2.2
- [helmet](https://npm.io/package/helmet.md) 4.4.1
- [lodash](https://npm.io/package/lodash.md) 4.17.21
- [mkdirp](https://npm.io/package/mkdirp.md) 1.0.4
- [rollup](https://npm.io/package/rollup.md) 2.33.3
- [express](https://npm.io/package/express.md) 4.17.1
- [chokidar](https://npm.io/package/chokidar.md) 3.5.1
- [get-port](https://npm.io/package/get-port.md) 5.1.1
- [minimatch](https://npm.io/package/minimatch.md) 3.0.4
- [@lwc/errors](https://npm.io/package/@lwc/errors.md) 2.2.5
- [compression](https://npm.io/package/compression.md) 1.7.4
- [folder-hash](https://npm.io/package/folder-hash.md) 4.0.1
- [@webruntime/api](https://npm.io/package/@webruntime/api.md) 1.61.4
- [@webruntime/performance](https://npm.io/package/@webruntime/performance.md) 1.61.4
- [@webruntime/webruntime-shim](https://npm.io/package/@webruntime/webruntime-shim.md) 1.61.4

## Recent versions

- 1.61.4 (latest) — 2021-07-23
- 0.61.2-234.9 (winter22) — 2021-09-15
- 1.61.5-alpha.1711 (canary) — 2021-07-27
- 0.49.6-232.2 (summer21) — 2021-04-26
- 0.42.6-230.3 (spring21) — 2021-02-11
- 0.33.24-228.1 (winter21) — 2020-08-07
- 0.29.13-226.1 (summer20) — 2020-04-13
- 0.61.2-234.8 — 2021-08-18
- 0.61.2-234.7 — 2021-08-12
- 0.61.2-234.6 — 2021-08-11
- 0.61.2-234.5 — 2021-08-04
- 0.61.2-234.4 — 2021-07-31
- 0.61.2-234.3 — 2021-07-30
- 0.61.2-234.2 — 2021-07-28
- 0.61.2-234.1 — 2021-07-28
- … 285 more at https://npm.io/package/@webruntime/server/versions

## README

# Lighting Web Runtime :: Server

The Lightning Web Runtime server is a pluggable application server.

An application is described using [configuration](#configuration) and enabled by the configured **services**.

[Addressable Services](../api/docs/classes/_services_addressable_service_.addressableservice.md) provide the basis for what LWC component dependencies can be supported by the application server.

## Getting Started

To install the core runtime package:

```
npm install @webruntime/server
```

## Startup script

The LWR Server API can be used to interact with a runnable app server. By default, the server, once created and started, will serve the application and components defined in the `webruntime-app.config.js`.

A simple startup script:

```
const { Server } = require('@webruntime/server');

const server = new Server();
server.initialize().then(() => {
    server.start();
});
```

## Project Setup

The project setup for a Lightning Web Application can be customized using the options in the `webruntime-app.config.js`.
However, the following is a recommendation for your project:

    .
    ├── dist                         # Build directory (buildDir) - containing static served content.
    ├── src
    │   ├── server                   # Runtime source code -- custom services, page resources, index.js
    │   ├── client                   # Client source code -- index.html, LWC components
    │   │   ├── modules              # Project source LWC components
    │   │   └── index.html           # Default application template
    └── webruntime-app.config.js     # Project Webruntime configuration
    └── package.json

## Configuration

Application configuration and customization is done via `webruntime-app.config.js`. Customization of what services the application requires, how the application components are bundled and provided to the client, and component compiler configuration can be set in `webruntime-app.config.js`.

A sample application configuration:

```javascript
/**
 * Sample App Configuration
 */

const { ComponentService, ImportMapService, AppBootstrapService } = require('@webruntime/services');

module.exports = {
    buildDir: 'dist',
    moduleDir: 'src/client/modules',

    // LWR Application configuration
    app: {
        defaultComponent: 'my/app',
        defaultTemplate: 'src/index.html',
    },

    // Addressable Services
    services: [ComponentService, ImportMapService, AppBootstrapService],

    // Component Bundling Configuration
    bundle: ['my/app'],

    // Registry of application bundle components, including shared lwc components
    // These specifiers are automatically included in the externals array below
    preloadModules: ['wire-service'],

    // These libraries will not be included in the page bundles
    externals: ['lwc', 'universal_container/loader'],
};
```

Additional details on [`Configuration Options`](../api/docs/modules/_config_.md)

## App Level Enhancements

Since the Runtime, encapsulates the application server hosting the application and its resource API's, it is possible to enhance and extend the underlying application by creating a server Extension.

You can use the extension to hook in additional services or API's to application server through either the [`extendApp`](docs/modules/_server_extensions_.md#ContainerAppExtension) or [`bootstrap`](docs/modules/_server_extensions_.md#ContainerBootstrapExtension) hooks.

It's recommended that your put your project-level server extensions alongside the other Runtime source code.

    .
    ├── src
    │   ├── server
    │   │   ├── extension.js        # Project server extension

### Configuration

The extensions are configured as a part of the `webruntime-app.config.js`.

```
module.exports = {
    ...
    server: {
        extensions: ["src/server/extensions.js"]
    }
}
```

### Usage Example

As one example of an extension, you can add your private APIs to the application server:

```
module.exports = {
    extendApp: ({ app, options }) => {
        app.use("/private/api", (req, res) => {
            res.send("Private .... shhhh");
        })
    }
}

```

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