Prerequisites
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher) - Download
- npm (comes with Node.js) or yarn
- Git (optional, for version control)
Installation Steps
1. Install Dependencies
# Navigate to the project directory
cd nest.js
# Install all dependencies
npm install
2. Start the Development Server
# Start the NestJS backend in development mode
npm run start:dev
The server will start on http://localhost:3000
3. Access the Frontend
Once the server is running, open your browser and navigate to:
http://localhost:3000/public/index.html
Project Structure
nest.js/
├── 01-beginner/ # Beginner tutorials
├── 02-intermediate/ # Intermediate concepts
├── 03-advanced/ # Advanced topics
├── examples/
│ ├── backend/ # Complete NestJS backend
│ │ └── src/
│ │ ├── main.ts # Application entry point
│ │ ├── app.module.ts
│ │ ├── tasks/ # Tasks module
│ │ └── users/ # Users module
│ └── frontend/ # HTML/CSS/JavaScript frontend
│ ├── index.html
│ ├── styles.css
│ └── app.js
├── package.json
└── README.md
Available Scripts
npm run start- Start the applicationnpm run start:dev- Start in development mode with hot reloadnpm run start:debug- Start in debug modenpm run start:prod- Start in production modenpm run build- Build the applicationnpm run test- Run unit testsnpm run test:e2e- Run end-to-end testsnpm run lint- Run ESLint
API Endpoints
Tasks API
GET /api/tasks- Get all tasksGET /api/tasks/:id- Get a specific taskPOST /api/tasks- Create a new taskPUT /api/tasks/:id- Update a taskDELETE /api/tasks/:id- Delete a taskOPTIONS /api/tasks- CORS preflight
Users API
GET /api/users- Get all usersGET /api/users/:id- Get a specific userPOST /api/users- Create a new userPUT /api/users/:id- Update a userDELETE /api/users/:id- Delete a userOPTIONS /api/users- CORS preflight
Testing the API
Using the Frontend
The easiest way to test the API is through the provided frontend interface at http://localhost:3000/public/index.html.
Using cURL
# Get all tasks
curl http://localhost:3000/api/tasks
# Get a specific task
curl http://localhost:3000/api/tasks/1
# Create a task
curl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-d '{"title":"New Task","description":"Task description","completed":false}'
# Update a task
curl -X PUT http://localhost:3000/api/tasks/1 \
-H "Content-Type: application/json" \
-d '{"title":"Updated Task","completed":true}'
# Delete a task
curl -X DELETE http://localhost:3000/api/tasks/1
# Test OPTIONS (CORS preflight)
curl -X OPTIONS http://localhost:3000/api/tasks \
-H "Origin: http://localhost:3000" \
-H "Access-Control-Request-Method: POST"
Using Postman
- Import the collection (if available)
- Set the base URL to
http://localhost:3000/api - Test each endpoint
Troubleshooting
Port Already in Use
If port 3000 is already in use, you can change it:
-
Set an environment variable:
bash PORT=3001 npm run start:dev -
Or modify
examples/backend/src/main.ts:typescript const port = process.env.PORT || 3001;
CORS Issues
If you encounter CORS errors, ensure:
- The CORS configuration in
main.tsincludes your frontend origin - The frontend is accessing the correct API URL
- OPTIONS requests are properly handled
Module Not Found Errors
If you see module not found errors:
# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
Learning Path
- Start Here: Read
01-beginner/README.md - Practice: Work through the examples in
examples/ - Progress: Move to
02-intermediate/README.md - Master: Complete
03-advanced/README.md - Build: Create your own NestJS application
Next Steps
- Read the Beginner Guide
- Explore the Complete Examples
- Check out the NestJS Official Documentation
Support
For issues or questions: - Check the NestJS Documentation - Review the tutorial materials in this repository - Check the examples for working code
Happy Learning! 🚀