Back to blog

Complete guide to generate your first Node.js project using PEST.js framework.
Prerequisites
- Node.js v16 or higher
- npm or yarn
- Git
Step 1: Run the Framework
# Navigate to framework directory
cd pest.js
# Run the framework
./pestjs
Step 2: Follow the Prompts
The framework will ask for:
Project name (default: pestjs-app): my-api
GitHub username (default: your-username): yourusername
Step 3: Navigate to Generated Project
# Navigate to your project
cd my-api
# Install dependencies
npm install
Step 4: Start Development
# Start development server
npm run dev
Your server will be running at http://localhost:3000
Generated Files Overview
package.json
{
"name": "my-api",
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon --exec ts-node src/app.ts",
"build": "tsc",
"test": "jest",
"lint": "eslint . --ext .ts"
}
}
src/app.ts
import express from 'express';
import cors from 'cors';
import helmet from 'helmet';
const app = express();
app.use(helmet());
app.use(cors());
app.use(express.json());
app.get('/', (_, res) => {
res.json({
message: 'Welcome to my-api API',
version: '1.0.0'
});
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Available Scripts
npm run dev
- Start development server with hot reloadnpm run build
- Build TypeScript to JavaScriptnpm start
- Start production servernpm test
- Run Jest testsnpm run lint
- Run ESLint
Project Structure
my-api/
├── src/
│ ├── app.ts # Main application
│ ├── config/ # Configuration files
│ ├── features/ # Feature modules
│ ├── middleware/ # Custom middleware
│ ├── utils/ # Utility functions
│ └── types/ # TypeScript types
├── tests/ # Test files
├── package.json # Dependencies
├── tsconfig.json # TypeScript config
├── .eslintrc.json # ESLint config
└── .env # Environment variables
Adding Features
Create a New Route
// src/features/users/routes/users.ts
import { Router } from 'express';
const router = Router();
router.get('/', (_, res) => {
res.json({ users: [] });
});
export default router;
Add Middleware
// src/middleware/auth.ts
import { Request, Response, NextFunction } from 'express';
export const authMiddleware = (req: Request, res: Response, next: NextFunction) => {
// Authentication logic
next();
};
Testing
// src/__tests__/app.test.ts
import request from 'supertest';
import express from 'express';
const app = express();
app.get('/', (_, res) => {
res.json({ message: 'Welcome to API' });
});
describe('App', () => {
it('should return welcome message', async () => {
const response = await request(app).get('/');
expect(response.status).toBe(200);
expect(response.body.message).toContain('Welcome');
});
});
Environment Configuration
# .env
NODE_ENV=development
PORT=3000
Git Integration
The framework automatically:
- Initializes git repository
- Creates initial commit
- Sets up .gitignore
git status
git log --oneline
Next Steps
- Add Routes: Create new API endpoints
- Database: Integrate with MongoDB, PostgreSQL, etc.
- Authentication: Add JWT or session-based auth
- Testing: Write unit and integration tests
- Deployment: Deploy to Heroku, Vercel, or AWS
Troubleshooting
Common Issues
Port already in use:
# Change port in .env
PORT=3001
TypeScript errors:
# Check tsconfig.json
npm run build
ESLint errors:
# Fix linting issues
npm run lint -- --fix
Framework Benefits
- Fast Setup: Generate projects in seconds
- Type Safety: Full TypeScript support
- Testing Ready: Jest configuration included
- Code Quality: ESLint setup
- Git Ready: Automatic repository initialization
- Minimal Dependencies: Only essential packages