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
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"
}
4. Run saksh-crud
Navigate to your project directory in the terminal or command prompt and run:
saksh-crud
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
:
- Run the Command:
saksh-crud
- 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):
-
Check the Output:
- The generated file will be located in
./routes/userRoutes.js
.
- The generated file will be located in
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! π
Top comments (0)