npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@glorious/crud

v0.2.0

Published

A bare minimum and extensible crud generator

Downloads

6

Readme

Glorious Crud

A bare minimum and extensible crud generator.

CircleCI codecov

Installation

npm install @glorious/crud --save

Usage

Basic

The purpose of this lib is to remove all the effort involved in creating a default crud as well as keeping everything under your control through its options.

const express = require('express');
const GCrud = require('@glorious/crud');

const app = express();
const gCrud = new GCrud('databaseUrl', 'databaseName', app);

// The line below will make the following endpoints available:
// GET    /beers
// GET    /beers/:id
// POST   /beers
// PUT    /beers/:id
// DELETE /beers/:id
const beersResource = gCrud.build('beers');

// From here, you can add any other custom endpoint you need.
beersResource.get('/beers/:id/awards', (req, res) => {
  // Your specific needs go here.
});

app.listen(9000, () => {
  console.log(`Running on port 9000...`);
});

Options

Using options, you can override any method by doing as follows:

const options = {
  get: (req, res) => {
    // This implementation will override get method.
    // The same can be done for any other method:
    // post, put, delete.
  }
}

const beersResource = gCrud.build('beers', options);

You can also set listeners to be called on success or on error of some method:

const options = {
  // Executes after every successful get request
  onGetSuccess: (req, res, response) => {
    // response is an object containing "status" (200) and "body".
  },
  // Executes after every failed get request
  onGetError: (req, res, err) => {
    // err is an object containing "status" (4xx or 5xx) and "body".
  },
  // Executes after every successful post request
  onPostSuccess: (req, res, response) => {
    // response is an object containing "status" (201) and "body".
  },
  // Executes after every failed post request
  onPostError: (req, res, err) => {
    // err is an object containing "status" (4xx or 5xx) and "body".
  },
  // Executes after every successful put request
  onPutSuccess: (req, res, response) => {
    // response is an object containing "status" (204).
  },
  // Executes after every failed put request
  onPutError: (req, res, err) => {
    // err is an object containing "status" (4xx or 5xx) and "body".
  },
  // Executes after every successful delete request
  onDeleteSuccess: (req, res, response) => {
    // response is an object containing "status" (204).
  }
  // Executes after every failed delete request
  onDeleteError: (req, res, err) => {
    // err is an object containing "status" (4xx or 5xx) and "body".
  }
}

const beersResource = gCrud.build('beers', options);

Built-in Query Params

When querying resources, you can use some built-in query params:

$sortBy

Sort some collection by one of its attributes:

curl http://localhost:9000/beers?$sortBy=name

$order

Order a sorted request by asc or desc:

curl http://localhost:9000/beers?$sortBy=name&$order=desc

$limit

Limit the number of results:

curl http://localhost:9000/beers?$limit=1

Also, you can use any resource attribute name as a filter:

curl http://localhost:9000/beers?name=Opa%20Bier

Contributing

  1. Install Node. Download the "Recommend for Most Users" version.

  2. Clone the repo:

git clone [email protected]:glorious-codes/glorious-crud.git
  1. Go to the project directory
cd glorious-crud
  1. Install the project dependencies
npm install
  1. run:
node src/app.js
  1. The API will be running on http://localhost:9000.

  2. Make some request to see the API in action:

curl http://localhost:9000/beers \
  -H 'content-type: application/json' \
  -d '{ "name":"Opa Bier" }'

NOTE Check out below how to configure MongoDB on your machine before making any request to the API.

Database

  1. Install MongoDB following its website instructions.

  2. Create a database called gcrud.

  3. Create a collection called beers.

  4. Start mongo on the default port(27017): Type mongod on your terminal.

Tools

  1. Postman is an awesome tool that makes API development a breeze.

  2. MongoDB Compass is the prettiest MongoDB UI client I have ever seen.

Deployment Services

The services I recommend to get your ideas out of your head are:

  1. WeDeploy (API)
  • 1 GB Transfer, 1 GB Memory, 1 CPU, 512 MB Storage for $0/mo
  1. MongoDB Atlas (Database)
  • 512 MB Storage, 3 node replica set for $0/mo