0.0.2 ā¢ Published 1 year ago
cthulhu.js v0.0.2
cthulhu.js
Fast, null-safe, model based api framework for Node.js
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.