1.0.9 • Published 3 years ago

@farazahmad759/dricup-crud-express v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

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.

1.0.9

3 years ago

1.0.8

3 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.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago