UNPKG

js-mvc-app

Version:

A CLI tool to scaffold complete Node.js MVC projects with TypeScript, just like Laravel

188 lines (143 loc) โ€ข 5.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getReadme = getReadme; function getReadme(projectName, config) { const { database, hasViews, viewEngine, extras } = config; return `# ${projectName} A Node.js MVC application built with TypeScript, Express.js, and ${database.toUpperCase()}. ## Features - ๐Ÿš€ **Express.js** with TypeScript - ๐Ÿ—๏ธ **MVC Architecture** with clear separation of concerns - ๐Ÿ” **JWT Authentication** with bcrypt password hashing - ๐Ÿ“Š **${database.toUpperCase()} Database** with ${database === 'mongodb' ? 'Mongoose' : 'Sequelize'} ORM - โœ… **Request Validation** with Joi - ๐Ÿ“ **Comprehensive Logging** with Winston - ๐Ÿ›ก๏ธ **Security** with Helmet, CORS, and Rate Limiting - ๐Ÿ”„ **Error Handling** middleware ${hasViews ? `- ๐ŸŽจ **View Engine** with ${viewEngine?.toUpperCase()}` : ''} ${extras.includes('docker') ? '- ๐Ÿณ **Docker** support with docker-compose' : ''} ${extras.includes('testing') ? '- ๐Ÿงช **Testing** setup with Jest and Supertest' : ''} ${extras.includes('linting') ? '- ๐ŸŽฏ **Code Quality** with ESLint and Prettier' : ''} ${extras.includes('husky') ? '- ๐Ÿช **Git Hooks** with Husky and lint-staged' : ''} ## Quick Start ### Prerequisites - Node.js (>= 16.0.0) - npm or yarn ${database === 'mongodb' ? '- MongoDB' : database === 'mysql' ? '- MySQL' : database === 'postgresql' ? '- PostgreSQL' : ''} ### Installation 1. Clone the repository: \`\`\`bash git clone <repository-url> cd ${projectName} \`\`\` 2. Install dependencies: \`\`\`bash npm install \`\`\` 3. Set up environment variables: \`\`\`bash cp .env.example .env \`\`\` 4. Configure your database connection in the \`.env\` file. ${database === 'mongodb' ? `5. Make sure MongoDB is running on your system.` : database === 'sqlite' ? `5. SQLite database will be created automatically.` : `5. Create your database and update the connection details in \`.env\`.`} 6. Start the development server: \`\`\`bash npm run dev \`\`\` The server will start on http://localhost:3000 ## API Endpoints ### Authentication - \`POST /api/auth/register\` - Register a new user - \`POST /api/auth/login\` - Login user - \`GET /api/auth/profile\` - Get user profile (protected) - \`PUT /api/auth/profile\` - Update user profile (protected) - \`PUT /api/auth/change-password\` - Change password (protected) ### Users - \`GET /api/users\` - Get all users (protected) - \`GET /api/users/search?q=query\` - Search users (protected) - \`GET /api/users/:id\` - Get user by ID (protected) - \`PUT /api/users/:id\` - Update user (protected) - \`DELETE /api/users/:id\` - Delete user (protected) ### Utilities - \`GET /health\` - Health check endpoint - \`GET /api\` - API information ## Project Structure \`\`\` src/ โ”œโ”€โ”€ config/ # Database and app configuration โ”œโ”€โ”€ controllers/ # Route controllers โ”œโ”€โ”€ models/ # Database models โ”œโ”€โ”€ routes/ # Express routes โ”œโ”€โ”€ middlewares/ # Custom middleware โ”œโ”€โ”€ utils/ # Utility functions ${hasViews ? 'โ”œโ”€โ”€ views/ # Template files' : ''} ${hasViews ? 'โ”œโ”€โ”€ public/ # Static assets' : ''} โ””โ”€โ”€ app.ts # Application entry point \`\`\` ## Scripts - \`npm run dev\` - Start development server with hot reload - \`npm run build\` - Build for production - \`npm start\` - Start production server ${extras.includes('testing') ? '- `npm test` - Run tests' : ''} ${extras.includes('testing') ? '- `npm run test:watch` - Run tests in watch mode' : ''} ${extras.includes('testing') ? '- `npm run test:coverage` - Run tests with coverage' : ''} ${extras.includes('linting') ? '- `npm run lint` - Run ESLint' : ''} ${extras.includes('linting') ? '- `npm run lint:fix` - Fix ESLint errors' : ''} ${extras.includes('linting') ? '- `npm run format` - Format code with Prettier' : ''} ## Environment Variables Copy \`.env.example\` to \`.env\` and configure: \`\`\`env NODE_ENV=development PORT=3000 JWT_SECRET=your-super-secret-jwt-key ${database === 'mongodb' ? 'MONGODB_URI=mongodb://localhost:27017/nodeapp' : 'DATABASE_URL=your-database-connection-string'} \`\`\` ## Authentication This API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header: \`\`\` Authorization: Bearer <your-jwt-token> \`\`\` ## Error Handling The API uses consistent error response format: \`\`\`json { "success": false, "error": "Error message", "details": [...] // Additional error details if available } \`\`\` ## Logging Application uses Winston for logging. Logs are written to: - Console (development) - \`logs/combined.log\` (all logs) - \`logs/error.log\` (error logs only) ${extras.includes('docker') ? ` ## Docker Build and run with Docker: \`\`\`bash docker-compose up --build \`\`\` ` : ''} ${extras.includes('testing') ? ` ## Testing Run the test suite: \`\`\`bash # Run all tests npm test # Run tests in watch mode npm run test:watch # Run tests with coverage npm run test:coverage \`\`\` ` : ''} ## Contributing 1. Fork the repository 2. Create your feature branch (\`git checkout -b feature/amazing-feature\`) 3. Commit your changes (\`git commit -m 'Add some amazing feature'\`) 4. Push to the branch (\`git push origin feature/amazing-feature\`) 5. Open a Pull Request ## License This project is licensed under the MIT License. `; } //# sourceMappingURL=readme.js.map