open-index/open-npm huggingface dataset:
npm package: @lukas3674/hbs-web-server
Description: A simple js web-server with hbs
Author: Lukas Hassler
Latest version: 1.1.2


# Simple JS Web-Server with HBS

## Usage:
#### Folder-Structure
```
>your_project
    >hbs
        >layouts
            >layout.hbs
        >public
            >js
                script.js
            ...
        >views
            >view.hbs
    >index.js
    >...
```

#### index.js
```js

const WS = require(`@lukas3674/hbs-web-server`);
const path = require(`path`);

const ws = new WS({
    port: 8888,
    cookieKey: `justSomeRandomKey`,
    hbsDir: path.join(__dirname, `hbs`),
}).start();

ws.get(`/`, (req, res) => {
    res.render(`view`, {
        title: `Test Website`,
        text: `My test website text ...`
    });
});

ws.get(`/stop`, (req, res) => {
    res.send(`stopped`);
    ws.stop();
});
```

#### layout.hbs
```html
<!DOCTYPE html>
<html style="background-color: #000000">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src="js/script.js"></script>

        {{#if title}}
            <title>{{title}}</title>
        {{/if}}
    </head>
    <body>
        {{{body}}}
    </body>
</html>
```

#### view.hbs
```html
<div style="color: #ffffff">
    {{#if text}}
        <h1 style="text-align: center">{{text}}</h1>
    {{/if}}
</div>
```

#### script.js
```js
console.log(`Hello Website!`);
```