@lukas3674/hbs-web-server

1.1.2 • Public • Published

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

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

<!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

<div style="color: #ffffff">
    {{#if text}}
        <h1 style="text-align: center">{{text}}</h1>
    {{/if}}
</div>

script.js

console.log(`Hello Website!`);

Readme

Keywords

Package Sidebar

Install

npm i @lukas3674/hbs-web-server

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

7.03 kB

Total Files

8

Last publish

Collaborators

  • lukas3674