0.0.2 ā€¢ Published 1 year ago

cthulhu.js v0.0.2

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
1 year ago

cthulhu.js

Fast, null-safe, model based api framework for Node.js

npm npm bundle size npm

const cthulhu = require('cthulhu.js');
const app = cthulhu();

app.endpoint('/supporters', {
    'GET': function(res, _req) {
        return res.json(supporters).status(200);
    },
    'POST': function(res, req) {
        supporters.push(req.body);
        return res.message('Supporter added').status(200);
    },
    'PATCH': function(res, req) {
        if (req.params.id > supporters.length) { 
            return res.error(`Supporter with id ${req.params.id} does not exist`).status(404);
        } else {
            supporters[req.params.id] = req.body;
            return res.message(`Supporter "${req.params.id}" updated`).status(200);
        }
    },
});

app.listen(80);

āš™ļø Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

npm i cthulhu.js

āœØ Features

  • Null-safety (Never leave your end-users with a server error)
  • Model-based returns (Keep your outputs standardized)
  • Ensured high performance
  • Simple routing
  • Recognisable syntax (Easy to learn for express.js developers)
  • File structure friendly

šŸ§™ File structure wizard

Instead of including multiple route files (registration.js, login.js, 2fa.js) for the same endpoint, why not include one (authentication.js)? Now you can have clean looking file structure instead of thousand-line files including hundreds of routes.

file structure

my-app/
ā”œā”€ node_modules/
ā”œā”€ routes/
ā”‚  ā”œā”€ authentication.js
ā”‚  ā”œā”€ authentication /
ā”‚  ā”‚  ā”œā”€ registration.js
ā”‚  ā”‚  ā”œā”€ login.js
ā”‚  ā”‚  ā”œā”€ 2fa.js
ā”œā”€ index.js
ā”œā”€ .gitignore
ā”œā”€ package.json

authentication.js

const cthulhu = require('cthulhu.js');
const wizard = cthulhu.wizard();

module.exports = wizard.directory('/authentication');

index.js

/**
 * Routing middle ware
 * @param {string} route - The route that the traffic will visit. (e.g: example.com/authentication)
 * @param {Object} require - Required wizard file.
 */
app.use('/authentication', require('./routes/authentication.js'));

šŸ“œ licensing

                    GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.
0.0.1

1 year ago

0.0.2

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago