Step-by-Step Guide to Using saksh-crud

susheel_kumar

Susheel kumar

Posted on September 19, 2024

Step-by-Step Guide to Using saksh-crud

Step-by-Step Guide to Using saksh-crud

1. Install Node.js and npm

Before you can use saksh-crud, ensure you have Node.js and npm installed on your system. You can download and install them from the official Node.js website.

2. Install saksh-crud Globally

Open your terminal or command prompt and run the following command to install saksh-crud globally:

npm install -g saksh-crud
Enter fullscreen mode Exit fullscreen mode

3. Create a Configuration File (Optional)

You can create a configuration file named saksh-crud.config.json in your project directory to save your preferences. This file is optional but can save you time by pre-filling some of the prompts.

Example saksh-crud.config.json:

{
  "defaultOutputDir": "./generated",
  "includeAuth": true,
  "customTemplateDir": "./custom-templates"
}
Enter fullscreen mode Exit fullscreen mode

4. Run saksh-crud

Navigate to your project directory in the terminal or command prompt and run:

saksh-crud
Enter fullscreen mode Exit fullscreen mode

5. Follow the Prompts

You will be prompted to enter various details. Follow the prompts to generate your CRUD routes:

  • Enter the full path to the model file: Provide the path to your Mongoose model file (e.g., /path/to/User.js).
  • Do you want to include authentication checks?: Choose whether to include authentication checks.
  • Enter the output directory: Specify the directory where the generated routes file should be saved.
  • Enter the directory for custom templates: If you have custom templates, provide the directory path. Otherwise, leave it blank to use the default templates.

6. Check the Generated Files

After completing the prompts, saksh-crud will generate the routes file in the specified output directory. The generated file will include the necessary CRUD operations based on your model.

7. Customize as Needed

You can further customize the generated routes file as needed. The generated file will include placeholders for your model and authentication logic if selected.

Example Usage

Here’s an example of how you might use saksh-crud:

  1. Run the Command:
   saksh-crud
Enter fullscreen mode Exit fullscreen mode
  1. Follow the Prompts:
   ? Enter the full path to the model file (e.g., /path/to/User.js): ./models/User.js
   ? Do you want to include authentication checks? Yes
   ? Enter the output directory: ./routes
   ? Enter the directory for custom templates (leave blank to use default templates):
Enter fullscreen mode Exit fullscreen mode
  1. Check the Output:
    • The generated file will be located in ./routes/userRoutes.js.

Troubleshooting

  • Template File Not Found: Ensure the template files are located in the correct directory (node_modules/saksh-crud/templates or your custom template directory).
  • Path Issues: Make sure the global npm bin directory is in your system's PATH.

If you encounter any issues or have questions, feel free to reach out for support!


Happy coding! 😊

💖 💪 🙅 🚩
susheel_kumar
Susheel kumar

Posted on September 19, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related