Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
hapi-quick-api-mongoose
Advanced tools
Quick Hapijs REST APIs with mixed Mongoose Schema and Joi
This package will simply convert passed schema configs to APIs in HapiJS with the help of get-it-ready.
The Schema Config should look like this:
//Person.js
var Mongoose = require('mongoose'),
Schema = Mongoose.Schema;
var Joi = require('joi');
let schema = {
firstName: { type: String, required: true, joi: Joi.string() },
lastName: { type: String, required: true, joi: Joi.string() },
photo: { type: String, required: false, joi: Joi.string() },
createdOn: { type: Date, required: false, default: Date.now, joi: Joi.date() }
}
export default {
definition: schema,
name: 'Person',
version: '0.1.0'
}
And in the HapiJS server can be simply coded in following way:
//index.js
//THIS FILE WILL BE BABEL TRANSPILED
import Hapi from 'hapi';
import Inert from 'inert';
import Vision from 'vision';
import Mongoose from 'mongoose';
const HapiSwagger = require('hapi-swagger');
import person from './Person';
const hapiQuickApiMongoose = require('hapi-quick-api-mongoose');
var config = {
server: {
host: '0.0.0.0',
port: process.env.PORT || 8000
}
};
// Create a server with a host and port
const server = new Hapi.Server();
server.connection(config.server);
//Connect and create placeholders
server.app.models = {};
server.app.db = Mongoose.createConnection(uri);
server.app.db.on('error', console.error.bind(console, 'connection error'));
server.app.db.once('open', function callback() {
console.log("Connection with database succeeded.");
});
//Register the plugins/modules
server.register([
Inert,
Vision,
{
'register': HapiSwagger,
'options': {
info: {
title: 'API Documentation',
version: 0.1.0,
}
}
},
{
register: hapiQuickApiMongoose,
options: {
connection: server.app.db,
models: [person]
}
}], err => {
console.log(err)
}
);
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
Now head over to browser on url http://localhost:8000/documentation and see the magic.
FAQs
Quick Hapijs REST APIs with mixed Mongoose Schema and Joi
We found that hapi-quick-api-mongoose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.