A CLI tool to generate backend structures for Node.js applications with support for multiple databases and a visually appealing user interface.
BackTool simplifies the process of setting up a Node.js backend by generating a complete project structure, including a server entry point, models, database configuration, controllers, routes, middleware, and a customized package.json. It supports MongoDB, PostgreSQL, MySQL, and SQLite, allowing developers to quickly scaffold a backend tailored to their preferred database.
- Database Support: Generates configurations and models for MongoDB, PostgreSQL, MySQL, and SQLite.
- Language Support: Generates projects in both JavaScript and TypeScript with proper configurations.
- Interactive Prompts: Uses
inquirerfor styled, user-friendly prompts with custom prefixes and validation. - Visual Feedback: Includes an ASCII art banner (
figlet), colored output (chalk), and progress spinners (ora). - Non-Interactive Mode: Supports command-line arguments for automation (e.g.,
backtool --project my-app --database MongoDB). - Complete Backend Structure: Creates
server.js,package.json, and directories formodels,config,controllers,routes, andmiddleware. - Customized package.json: Generates a
package.jsonwith the project name, scripts (start,dev), and dependencies. - Automatic Package Installation: Installs required dependencies (e.g.,
express,mongoose,pg,mysql2,sqlite3) andnodemonas a dev dependency. - Git Initialization: Automatically initializes a Git repository in the generated project with proper .gitignore setup.
- Environment Configuration: Includes
.env.exampletemplate that gets copied to.envfor easy environment setup. - File Overwrite Protection: Prompts users before overwriting existing files (e.g.,
server.js,package.json, model files). - Extensible: Easily add new databases or structure components by updating the template folder.
Install BackTool globally to use it from any directory:
npm install -g backtoolAlternatively, clone the repository and link it locally:
git clone https://github.com/Amanbig/backtool.git
cd backtool
npm install
npm linkRun BackTool without arguments to use interactive prompts:
backtoolor directly using:
npx backtool@latestThis will display an ASCII banner and prompt for:
- Project name (e.g.,
my-app) - Database choice (MongoDB, MySQL, PostgreSQL, or SQLite)
Specify options directly to skip prompts:
backtool --project my-app --database MongoDB-p, --project <name>: Specify the project name (default:my-app).-d, --database <type>: Specify the database (MongoDB, MySQL, PostgreSQL, SQLite).-l, --language <type>: Specify the language (JavaScript, TypeScript).-f, --force: Force overwrite of existing files without prompting.-u, --uri <uri>: Specify database connection URI.-v, --version: Display the version number.-h, --help: Show help information.
Running BackTool creates one of the following directory structures based on the chosen language:
my-app/
├── server.js
├── package.json
├── .env
├── .gitignore
├── config/
│ └── database.js
├── models/
│ └── user.<database>.js
├── controllers/
│ └── authController.js
├── routes/
│ └── auth.js
├── middleware/
│ └── auth.js
├── node_modules/
└── .git/
my-app/
├── server.ts
├── package.json
├── tsconfig.json
├── .env
├── .gitignore
├── src/
│ ├── config/
│ │ └── database.ts
│ ├── models/
│ │ └── user.<database>.ts
│ ├── controllers/
│ │ └── authController.ts
│ ├── routes/
│ │ └── auth.ts
│ ├── middleware/
│ │ └── auth.ts
│ └── types/
│ └── express.d.ts
├── dist/ # Compiled JavaScript
├── node_modules/
└── .git/
- server.[js|ts]: Entry point for the Node.js application, setting up the Express server and routes.
- package.json: Includes project configuration, scripts, and dependencies. For TypeScript projects, includes additional scripts for building and type checking.
- tsconfig.json: (TypeScript only) TypeScript compiler configuration.
- config/database.[js|ts]: Database connection and table initialization.
- models/: Database models with database-specific implementations.
- controllers/: Request handling logic including authentication.
- routes/: API route definitions.
- middleware/: Custom middleware (e.g., authentication).
- types/: (TypeScript only) Type definitions and declarations.
- dist/: (TypeScript only) Compiled JavaScript output.
The users table/model includes fields: id, username, email, password, and created_at.
After generating the project, navigate to the project directory and run:
# For JavaScript projects
npm start
# For TypeScript projects
npm start # Runs with ts-node
npm run build # Compiles TypeScript to JavaScript
npm run start:prod # Runs the compiled JavaScriptFor development with auto-restart on file changes:
npm run dev # Works for both JavaScript and TypeScript- MongoDB: Uses
mongoosefor schema-based modeling. - PostgreSQL: Uses
pgwith a connection pool and SQL queries. - MySQL: Uses
mysql2with a promise-based connection pool. - SQLite: Uses
sqlite3andsqlitefor lightweight, file-based storage.
BackTool installs the following dependencies in the generated project:
- Core Dependencies:
express,dotenv,cors,jsonwebtoken - Database-specific Dependencies:
- MongoDB:
mongoose,bcryptjs - PostgreSQL:
pg,bcryptjs - MySQL:
mysql2,bcryptjs - SQLite:
sqlite3,bcryptjs
- MongoDB:
- Common:
nodemon - TypeScript-specific (when TypeScript is selected):
typescriptts-node@types/node@types/express@types/cors@types/jsonwebtoken@types/bcryptjs- Database-specific types (e.g.,
@types/mongoose,@types/pg)
To contribute or modify BackTool:
- Clone the repository:
git clone https://github.com/Amanbig/backtool.git
- Install dependencies:
npm install
- Update the
backtool_folderdirectory with custom templates (e.g.,server.js, models). - Test locally:
npm link backtool --project test-app --database SQLite
MIT License
For issues or feature requests, open a ticket on the GitHub repository.