# squeakjs

> Squeak is a small and light weight caching webserver with powerful routing and view parsing magic.

Latest version **1.0.31** (published 2019-04-24) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install squeakjs
pnpm add squeakjs
yarn add squeakjs
bun add squeakjs
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.31 |
| Published | 2019-04-24 |
| First published | 2019-01-02 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 213.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | David Schaefer |
| Maintainers | quadband |
| Keywords | web server, expressless, view template, router |

## Links

- npm: https://www.npmjs.com/package/squeakjs
- Repository: https://github.com/quadband/squeakjs
- Homepage: https://github.com/quadband/squeakjs#readme
- Issues: https://github.com/quadband/squeakjs/issues
- npm.io page: https://npm.io/package/squeakjs

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.0.31 (latest) — 2019-04-24
- 1.0.30 — 2019-04-24
- 1.0.29 — 2019-04-03
- 1.0.28 — 2019-04-03
- 1.0.27 — 2019-03-09
- 1.0.26 — 2019-03-09
- 1.0.25 — 2019-01-14
- 1.0.24 — 2019-01-14
- 1.0.23 — 2019-01-14
- 1.0.22 — 2019-01-14
- 1.0.21 — 2019-01-14
- 1.0.20 — 2019-01-14
- 1.0.19 — 2019-01-14
- 1.0.18 — 2019-01-14
- 1.0.17 — 2019-01-14
- … 17 more at https://npm.io/package/squeakjs/versions

## README

SqueakJS
=======

## Installation
```$xslt
$ npm install squeakjs
```

## Example Usage
```$xslt
./
|-- dist/
    |-- client/
        |-- js/
            |-- home.js
        |-- styles/
            |-- home.css
            |-- layout.css
|-- src
    |-- squeak/
        |-- main.ts
        |-- interfaces/
        	|-- someapi.ts
        |-- views/
            |-- layout.html
            |-- index/
                |-- index.html
                |-- index.ts
    |-- server.ts
    |-- app.ts
    |-- tsconfig.json
```
---
#### tsconfig.json
```json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "experimentalDecorators": true,
    "lib": [
      "es2018",
      "scripthost",
      "dom"
    ],
    "sourceMap": false,
    "outDir": "../dist",
    "allowSyntheticDefaultImports": true
  },
  "files": [
    "./app.ts",
    "./squeak/main.ts",
    "./squeak/views/index/index.ts",
    "./squeak/views/interfaces/someapi.ts",
    "./server/server.ts"
  ]
}
```
---
#### server.ts
```typescript
import * as http from 'http';
import { serverIp, randomId } from 'squeakjs/lib/utilities';
import { SqueakServer } from 'squeakjs';

import { Squeak } from "../squeak/main";

export class Server {
    squeakServer: SqueakServer;
    instances: ServerInstances = {};

    constructor(){
        this.squeakServer = new SqueakServer(Squeak);
    }

    createInstance(id: string = undefined, port: number = 8010,): string {
        if(id === undefined) id = randomId();
        this.instances[id] = http.createServer((req,res)=>{
            console.log(`Instance [${id}] Request: ${req.url}`);
            this.squeakServer.serve(req,res);
        }).listen(port);
        console.log(`Server instance [${id}] running at http://${serverIp(this.instances[id])}`);
        return id;
    }
}

export interface ServerInstances {
    [key: string]: any;
}
```
---
#### app.ts
```typescript
import { Server } from './server';
global['__basedir'] = __dirname;
const server = new Server();
let instance = server.createInstance('test', 8010);
```
---
#### main.ts
```typescript
import { SqueakMain, FileCacheStrategy, FileWatchStrategy } from 'squeakjs';

// Views
import { IndexView } from "./views/index";

// Interfaces
import { SomeApiInterface } from "./interfaces/someapi";

@SqueakMain({
    viewDir: __dirname + '/views',
    publicDir: './dist/client',
    squeakFile: __filename,
    fileCacheStrategy: FileCacheStrategy.onFirstLoad(),
    fileWatchStrategy: FileWatchStrategy.immediate(),
    declarations: [
        IndexView,
        SomeApiInterface
    ],
    roots: [
        {selector: 'layout', file: 'layout.html'}
    ]
}) export class Squeak {}
```
---
#### someapi.ts
```typescript
import { SqueakInterface, OnGet } from 'squeakjs';

@SqueakInterface({
    squeakName: 'api',
    squeakPath: __dirname,
    squeakFile: __filename,
    urlPath: '/api'
}) export class SomeApiInterface implements OnGet {
    
    constructor(){}

    onGet(req,res){
        console.log('Test Get');
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end('testApiInterface', 'utf-8');
    }
}
```
---
#### index.ts
```typescript
import { SqueakView } from 'squeakjs';

@SqueakView({
    squeakName: 'index',
    squeakPath: __dirname,
    squeakFile: __filename,
    urlPath: '/',
    title: 'Squeak Home',
    views: [
        {selector: 'index', file: 'index.html'}
    ],
    styleUrls: ['/styles/home.css'],
    clientJs: ['/js/home.js']
}) export class IndexView {
    
    constructor(){}
    
}
```
---
#### layout.html
```html
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Default Title</title>
		<link rel="stylesheet" href="/styles/layout.css">
	</head>
	<body>
		<s-render-outlet></s-render-outlet>
	</body>
</html>
```
---
#### index.html
```html
<s-template s-rendersat="layout">
	<h1>Hello, Squeak!</h1>
</s-template>
```

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