npm.io
1.0.1 • Published 4 years ago

@aylias/quickserve

Licence
ISC
Version
1.0.1
Deps
1
Size
3 kB
Vulns
0
Weekly
0

QuickServe wraps the express functions into a simpler to use format, allowing you to use less lines of code to achieve the same result.

const qs = require('@aylias/quickserve')

const server = new qs(8055); // Create an instance of quickserve with the desired port

// Use get and post methods like normal
server.get('/', (req, res) => {
    res.writeHeader(200, { "Content-Type": "text/html" });
    res.write("<h1>You used a normal get method</h1>");
    res.end();
})

server.post('/', (req, res) => {
    res.writeHeader(200, { "Content-Type": "text/html" });
    res.write(`<h1>Your name is ${req.body.name}</h1>`);
    req.end();
})


// Automatically get and serve files of type html, css, json, and javascript
server.getHTML('/main', './main.html');
server.getCSS('/main.css', './main.css');
server.getJSON('/stats', './stats.json');
server.getJS('/main.js', './main.js');

server.serve();