# @tws-js/server

> Type-Safe Web Server Framework

Latest version **2.2.1** (published 2025-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tws-js/server
pnpm add @tws-js/server
yarn add @tws-js/server
bun add @tws-js/server
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2025-01-05 |
| First published | 2023-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 78.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | sergiodeveloper |

## Links

- npm: https://www.npmjs.com/package/@tws-js/server
- Repository: https://github.com/sergiodeveloper/tws
- Homepage: https://github.com/sergiodeveloper/tws#readme
- Issues: https://github.com/sergiodeveloper/tws/issues
- npm.io page: https://npm.io/package/@tws-js/server

## Dependencies (3)

- [express](https://npm.io/package/express.md) ^4.21.2
- [socket.io](https://npm.io/package/socket.io.md) ^4.8.1
- [@tws-js/common](https://npm.io/package/@tws-js/common.md) ^1.0.0

## Recent versions

- 2.2.1 (latest) — 2025-01-05
- 2.2.0 — 2025-01-05
- 2.1.0 — 2025-01-03
- 2.0.1 — 2024-12-31
- 2.0.0 — 2024-12-30
- 1.0.6 — 2024-11-04
- 1.0.5 — 2024-11-03
- 1.0.4 — 2024-04-12
- 1.0.3 — 2024-04-12
- 1.0.2 — 2023-07-20
- 1.0.1 — 2023-04-23
- 1.0.0 — 2023-04-22
- 0.2.0 — 2023-04-17
- 0.1.2 — 2023-02-05
- 0.1.1 — 2023-02-05
- … 1 more at https://npm.io/package/@tws-js/server/versions

## README

# TWS - Type-Safe Web Server Framework

[![Test](https://github.com/sergiodeveloper/tws/actions/workflows/test.yml/badge.svg)](https://github.com/sergiodeveloper/tws/actions/workflows/test.yml)
[![NPM](https://img.shields.io/npm/v/@tws-js/server)](https://www.npmjs.com/package/@tws-js/server)

<p align="center">
  <img alt="TWS Logo" height="150" src="https://user-images.githubusercontent.com/7635171/232378489-e32588ea-e76b-4fd9-9cad-14bfb045e7b3.svg" />
  <br>
  <b>TWS is a framework built with TypeScript to create type-safe web servers.</b>
</p>

This framework was created with the purpose of enhancing the developer and user experience when developing and communicating with strongly typed APIs.

## Usage

### Installation

```bash
npm install @tws-js/server
```

### Example

Start the server:

```typescript
import { Operation, Schema, HTTPServerHelper } from '@tws-js/server';

const schema = new Schema({
  hello: new Operation({
    input: {
      name: {
        type: 'string',
        required: true,
        description: 'The name to greet',
      },
    },
    output: {
      type: 'object',
      properties: {
        message: {
          type: 'string',
          description: 'The greeting message',
        },
      },
    },
    handler: ({ name }, metadata) => { // "name" automatically typed as string
      return {
        // Typescript will warn if "message" is not a string,
        // as required by the output
        message: `Hello ${name}`,
      };
    },
  }),
}, {
  logger: {
    error: (message) => console.error(message),
  },
  enablePlayground: true,
});

HTTPServerHelper.create({
  port: 3000,
  schema,
  path: '/tws',
});
```

Send a request to the server:

```bash
curl -X POST \
  http://localhost:3000/tws \
  -H "Content-Type: application/json" \
  -d '{ "operation": "hello", "input": { "name": "TWS" } }'
```

Check the response:

```json
{
  "data": {
    "message": "Hello TWS"
  }
}
```

## Collaborating

### Setup

```bash
nvm use 20
npm install
```

### Running

```bash
npm start
```

### Testing

```bash
npm run lint
npm test
```

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