aseasy
v1.0.7
Published
A production-ready backend framework with a simple DSL for building secure, scalable Node.js applications
Maintainers
Readme
easy.js - Production-Ready Backend Framework
A developer-friendly backend framework that transforms simple DSL syntax into fully functional, production-ready Node.js/Express applications with built-in security, validation, and database support.
🎯 What is easy.js?
easy.js simplifies backend development by letting you write backend applications in a clean, human-readable DSL instead of complex Express.js code. Write simple declarations, get a fully functional REST API with:
- Express.js server setup
- MongoDB & MySQL support
- JWT authentication
- Input validation
- Rate limiting & security headers
- CORS configuration
- Error handling
- Database migrations
⚡ Quick Start
Installation
npm install easy.jsCreate a Project
npx easyjs create my-api
cd my-api
npm install
npm startYour First API
Create app.easy:
START SERVER 3000
USE MONGODB mongodb://localhost:27017/mydb
MODEL users {
name: string
email: string
password: string
}
AUTH users BY jwt
GET /users FROM users
POST /users FROM users
PUT /users/:id FROM users
DELETE /users/:id FROM users
VALIDATE users {
email: required:email
password: required:min=6
name: required
}
PROTECT /usersRun it:
easyjs start app.easyYour API is now running on http://localhost:3000
📖 Language Syntax
Server Configuration
START SERVER <port>Example:
START SERVER 3000Database Configuration
USE MONGODB <connection_string>
USE MYSQL <connection_string>Examples:
USE MONGODB mongodb://localhost:27017/myapp
USE MYSQL mysql://root:password@localhost:3306/myappModel Definition
MODEL <name> {
field: type
field: type
}Supported types: string, number, boolean, date, object, array
Example:
MODEL users {
name: string
email: string
age: number
isActive: boolean
}Routes
<METHOD> <path> FROM <model>Methods: GET, POST, PUT, DELETE, PATCH
Examples:
GET /users FROM users
GET /users/:id FROM users
POST /users FROM users
PUT /users/:id FROM users
DELETE /users/:id FROM usersAuthentication
AUTH <model> BY jwtEnables JWT authentication for the specified model.
AUTH users BY jwtProtected Routes
PROTECT <path>Requires JWT token for access.
PROTECT /users
PROTECT /postsValidation Rules
VALIDATE <model> {
field: rule:rule
field: rule:rule
}Available rules:
required- Field is mandatoryemail- Valid email formatmin=N- Minimum length/valuemax=N- Maximum length/valuenumeric- Numeric values onlyalphanumeric- Letters and numbers onlyurl- Valid URL formatphone- Valid phone number
Example:
VALIDATE users {
email: required:email
password: required:min=6
age: numeric:min=18
name: required:min=2:max=50
}Middleware
USE LOGGER
USE AUTHBuilt-in middleware: LOGGER, AUTH, CORS, COMPRESSION
🏗️ Project Structure
easyjs/
├── cli/ # Command-line interface
├── parser/ # DSL parser & tokenizer
│ ├── Parser.js
│ ├── Tokenizer.js
│ └── ASTBuilder.js
├── compiler/ # Compiler to Express.js
│ └── Compiler.js
├── runtime/ # Runtime engine
│ └── RuntimeEngine.js
├── core/ # Core modules
│ ├── router.js # Route handler generation
│ ├── database.js # Database manager
│ ├── auth.js # Authentication & JWT
│ ├── validator.js # Input validation
│ ├── logger.js # Logging utility
│ └── middleware.js # Middleware factory
├── adapters/ # Database adapters
│ ├── mongodb.js
│ └── mysql.js
├── examples/ # Example applications
├── index.js # Entry point
├── package.json
└── README.md🔐 Security Features
Built-in Protections
- JWT Authentication: Secure token-based authentication
- Password Hashing: bcryptjs for secure password storage
- Rate Limiting: Protection against brute force attacks
- Helmet.js: Secure HTTP headers
- CORS: Configurable cross-origin resource sharing
- Input Validation: Comprehensive validation rules
- Input Sanitization: Automatic input cleaning
- SQL Injection Prevention: Parameterized queries
Environment Configuration
Create .env file:
JWT_SECRET=your-secure-secret-key
JWT_EXPIRY=24h
MONGODB_URL=mongodb://localhost:27017/myapp
MYSQL_URL=mysql://root:password@localhost:3306/myapp
DEBUG=false🗄️ Database Support
MongoDB
USE MONGODB mongodb://user:password@host:port/dbnameFeatures:
- Automatic schema generation
- Timestamps (createdAt, updatedAt)
- Mongoose integration
- Flexible document structure
MySQL
USE MYSQL mysql://user:password@localhost:3306/dbnameFeatures:
- Automatic table creation
- Connection pooling
- Prepared statements
- Transaction support ready
🔑 Authentication
Setup
AUTH users BY jwt
PROTECT /api/usersAPI Endpoints
Authentication is handled automatically via protected routes. Include JWT token:
Authorization: Bearer <token>User Management
Users model receives special handling:
- Password auto-hashing
- Token generation
- Session management
✅ Validation
Comprehensive input validation with clear error messages:
VALIDATE users {
email: required:email
password: required:min=6:max=128
age: numeric:min=18
}Error responses:
{
"success": false,
"error": "Validation failed",
"details": {
"email": ["email must be a valid email"],
"password": ["password must be at least 6 characters"]
}
}📡 API Response Format
Success Response
{
"success": true,
"data": { /* resource data */ }
}Error Response
{
"success": false,
"error": "Error message",
"timestamp": "2024-01-01T12:00:00.000Z"
}🛠️ CLI Commands
Create New Project
easyjs create <project-name>Start Production Server
easyjs start app.easyDevelopment Mode (Watch Mode)
easyjs dev app.easyBuild for Production
easyjs buildShow Version
easyjs --versionShow Help
easyjs --help📚 Complete Example
START SERVER 4000
USE MONGODB mongodb://localhost:27017/blog
MODEL posts {
title: string
content: string
author: string
published: boolean
views: number
}
MODEL comments {
postId: string
text: string
author: string
}
GET /posts FROM posts
GET /posts/:id FROM posts
POST /posts FROM posts
PUT /posts/:id FROM posts
DELETE /posts/:id FROM posts
GET /posts/:postId/comments FROM comments
POST /posts/:postId/comments FROM comments
DELETE /comments/:id FROM comments
VALIDATE posts {
title: required:min=3:max=200
content: required:min=10
author: required
}
VALIDATE comments {
text: required:min=1:max=1000
author: required
postId: required
}
PROTECT /posts
PROTECT /comments🚀 Deployment
Docker
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
ENV NODE_ENV=production
EXPOSE 3000
CMD ["npm", "start"]Environment Variables
Set before deployment:
JWT_SECRET=production-secret-key
MONGODB_URL=mongodb+srv://user:[email protected]/proddb
NODE_ENV=production🧪 Testing Your API
Get All Users
curl http://localhost:3000/usersCreate User
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "[email protected]",
"password": "securepass123"
}'Update User
curl -X PUT http://localhost:3000/users/123 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"name": "Jane Doe"
}'Delete User
curl -X DELETE http://localhost:3000/users/123 \
-H "Authorization: Bearer <token>"📝 Best Practices
- Environment Variables: Always use
.envfor sensitive data - Validation: Define comprehensive validation rules
- Security: Use strong JWT secrets in production
- Logging: Enable debug mode during development
- Database: Use connection strings with authentication
- Rate Limiting: Protect public endpoints from abuse
🐛 Troubleshooting
Database Connection Failed
- Check database service is running
- Verify connection string in
.env - Check firewall rules
Port Already in Use
easyjs start app.easy --port 3001Module Not Found
npm install
npm start📄 License
MIT License - Feel free to use in personal and commercial projects
🤝 Contributing
Contributions welcome! Submit issues and pull requests on GitHub.
📞 Support
For issues and questions:
- Open an issue on GitHub
- Check documentation
- Review examples directory
easy.js - Building backends has never been easier. ✨
