create-nexlify
v1.0.3
Published
A CLI tool to scaffold Node.js projects with TypeScript/JavaScript, databases, validators, and middlewares.
Maintainers
Readme
create-nexlify
A CLI tool to scaffolder Node.js projects with support for TypeScript or JavaScript, multiple databases, validators, middlewares, Swagger documentation, and Jest tests.
Features
- Languages: Generate projects in TypeScript or JavaScript.
- Multilinguism: Supports English and French for error messages and documentation.
- Databases: MongoDB, PostgreSQL, MySQL, or none.
- Validators: Zod, Joi, or none.
- Middlewares: Helmet, CORS, rate-limit, Morgan, compression, JWT authentication.
- Documentation: Optional Swagger UI for API endpoints.
- Testing: Jest with Supertest for API tests.
- Entities: Define custom entities with fields (e.g.,
Userwithname:string,email:string,password:string).
Installation
Install globally with npm:
npm install -g create-nexlifyOr use without installing via npx:
npx create-nexlifyUsage
Run the CLI to start the interactive setup:
create-nexlifyThe CLI will prompt you for configuration options:
- Language: Choose
FrançaisorEnglish. - Project Type: TypeScript or JavaScript.
- Project Name: e.g.,
my-api. - Description: Optional project description.
- Package Manager:
npm,yarn, orpnpm. - Database: MongoDB, PostgreSQL, MySQL, or None / Aucune.
- Database URL: e.g.,
postgres://user:pass@localhost:5432/my-api. - Validator: Zod, Joi, or None / Aucun.
- Swagger: Enable (
Oui) or disable (Non) Swagger. - Middlewares: Choose multiple (Helmet, CORS, JWT, etc.).
- JWT Secret: Required if JWT selected (e.g.,
mysecretkey). - Entities: Define entities and their fields (e.g.,
Userwithname:string,email:string,password:string). - Install Dependencies: Choose to install now (
Oui) or later (Non).
Example Interaction
? Quelle langue souhaitez-vous utiliser ? Français
? Quel type de projet voulez-vous créer ? TypeScript
? Quel est le nom de votre projet ? my-api
? Entrez une description du projet (optionnel) : API de gestion d'utilisateurs
? Quel gestionnaire de paquets ? npm
? Quelle base de données ? PostgreSQL
? Entrez l'URL de connexion (optionnel) : postgres://testuser:testpass@localhost:5432/my-api
? Quel validateur ? Joi
? Voulez-vous inclure la documentation Swagger ? Oui
? Quels middlewares ? Helmet, CORS, JWT
? Entrez une clé secrète pour JWT : mysecretkey
? Quelles entités ? User
? Quels champs pour User ? name:string,email:string,password:string
Génération des fichiers... ✅ Projet "my-api" généré avec succès !
? Voulez-vous installer les dépendances maintenant ? Oui
Installation des dépendances... ✅ Dépendances installées avec succès !Project Structure
my-api/
├── src/
│ ├── controllers/
│ │ └── userController.ts
│ ├── middlewares/
│ │ └── authMiddleware.ts
│ ├── models/
│ │ └── User.ts
│ ├── routes/
│ │ ├── authRoutes.ts
│ │ └── userRoutes.ts
│ ├── validators/
│ │ └── userValidator.ts
│ ├── index.ts
│ └── swagger.json
├── tests/
│ └── user.test.ts
├── .env
├── jest.config.ts
├── package.json
├── README.md
└── tsconfig.jsonRunning the Generated Project
cd my-apiInstall dependencies if not yet done:
npm installConfigure the database:
psql -U testuser -c "CREATE DATABASE my-api;"Update your .env file:
PORT=3000
DATABASE_URL=postgres://testuser:testpass@localhost:5432/my-api
JWT_SECRET=mysecretkeyCompile TypeScript (if applicable):
npm run buildStart the server:
npm start- Server: http://localhost:3000
- Swagger: http://localhost:3000/api-docs
Run tests:
npm testAPI Endpoints
POST /api/auth/register
Body:
{
"name": "John Doe",
"email": "[email protected]",
"password": "password123"
}Response:
{
"message": "Utilisateur enregistré",
"user": { ... }
}POST /api/auth/login
Body:
{
"email": "[email protected]",
"password": "password123"
}Response:
{
"token": "jwt-token"
}POST /api/users
Headers:
Authorization: Bearer <jwt-token>Body:
{
"name": "Jane Doe",
"email": "[email protected]",
"password": "password123"
}Response:
{
"name": "Jane Doe",
"email": "[email protected]",
...
}GET /api/users
Headers:
Authorization: Bearer <jwt-token>Response:
[
{
"name": "John Doe",
"email": "[email protected]",
...
}
]Configuration Details
.env File
PORT: Server port (default: 3000)DATABASE_URL: e.g.,postgres://user:pass@localhost:5432/dbJWT_SECRET: JWT token secret
tsconfig.json
- ES2020
- CommonJS
- Strict typing
- Output:
./dist
jest.config.ts
- Uses
ts-jest - Supports TypeScript testing
Troubleshooting
Syntax Errors in Generated Files
Check your version:
create-nexlify --versionUpdate:
npm install -g create-nexlify@latestDatabase Connection Errors
Ensure server is running and .env is correctly set.
For PostgreSQL:
psql -U testuser -h localhost -d my-apiTypeScript Compilation Errors
npm install
npm run buildCheck tsconfig.json.
Test Failures
Ensure you have:
npm install --save-dev jest ts-jest supertestVerify jest.config.ts.
Contributing
- Fork: https://github.com/Le-Sourcier/create-nexlify.git
- Create branch:
git checkout -b feature/your-feature - Commit:
git commit -m "Add your feature" - Push:
git push origin feature/your-feature - Open a Pull Request
License
This project is licensed under the MIT License. See the LICENSE file.
Support
For issues or feature requests, open an issue at:
