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

@farazahmad759/dricup-crud-express

v1.0.9

Published

A CLI to quickly create Express JS Api's

Downloads

14

Readme

dricup-crud-express

Create quick RESTful APIs using Express + Knex + Objection. A single command dricup-crud-express will generate

  • Migration files,
  • Model files,
  • Controller files, and
  • Express Route files

You will save hours of your development.

Use Cases

  • Build a Todo App in less than 5 minutes https://farazahmad759.medium.com/build-a-todo-app-in-less-than-5-minutes-in-node-express-ada63d7c54b9

Getting started

You get CRUD APIs in six simple steps.

Step 1

Install the package globally using

npm install -g @farazahmad759/dricup-crud-express

Step 2

Navigate to your Express project's root directory, and create schemas directory in <project_root>/db directory. It is the <project_root>/db/schemas directory where you will create .json schema files.

Your Express project directory structure should look like this

.
├── app.js
├── bin
│   └── www
└── db
    └── schemas
        ├── table_1_schema.json
        ├── table_2_schema.json
        └── table_3_schema.json

Step 3

Create schema file(s). A sample schema file for users SQL table is included below. Feel free to copy its content and modify as per your needs.

{
    "tableName": "users",
    "fields": [
        {
            "title": "name",
            "type": "string"
        },
        {
            "title": "username",
            "type": "string"
        },
        {
            "title": "email",
            "type": "string"
        },
        {
            "title": "password",
            "type": "string"
        }
    ]
}

Step 4

Run the following command

dricup-crud-express

and then install npm packages using

npm install

The dricup-crud-express command will generate the following files and directories.

db
--- migrations
------ create_table_users.js
--- models
------ users.js
--- controllers
------ users.js
routes
--- users.js
knexfile.js
ecag.config.json

Step 5

Open knexfile.js and adjust your database credentials. A sample configuration will be like this

client: "mysql",
connection: {
    host: "127.0.0.1",
    database: "express-test-app",
    user: "root",
    password: "password",
},
migrations: {
    directory: __dirname + "/db/migrations",
},
seeds: {
    directory: __dirname + "/db/seeds/development",
},

Step 6

In your app.js file, add the following two lines

/** ================
 *  your app.js file
 *  ================
 */


// some code

var usersRouter = require('./routes/users');
app.use('/users', usersRouter);

// even deliciuos code

Now start your Express App using npm start, and boom!!! your CRUD API is ready. dricup-crud-express provides the following routes

  • POST /users --- to create a new user
  • GET /users/:id --- to get a user by Id
  • PUT /users/:id --- to update a user by Id
  • DELETE /users/:id --- to delete a user by Id
  • GET /users --- to get all users (filters by each database column are already created for you)

Capabilities

  • I have described the capabilities of the dricup-crud-express in Build a Todo App in less than 5 minutes

  • There is much more you can do with it. Visit the db/ directory in your project root and explore the directories inside it, most notably the db/controllers directory.

  • Take a look at the todos controller file created by the package here. The controller file has five methods in it for CRUD operations.

    • createOne
    • getOne
    • updateOne
    • deleteOne
    • getAll

Feel free to modify any of the above methods according to your needs. You can even add more methods to your controllers if you want. dricup-crud-express provides you the boilerplate code for writing API's and thus saves so much of your precious time.

  • ecag.config.json file in the root of your project defines the paths where the files will be generated, which you can modify it as you want.

What is more?

This is just the starting. Several options will be added very soon to configure libraries such as Sequelize.

Feel free to request features, and I will be delighted to assist you in the issues you experience while using this package.