A TypeScript web server that generates Vite React TypeScript projects based on configuration input and returns them as downloadable zip files.
- ✅ npm verification - Ensures npm is installed on startup
- 🏗️ Project generation - Creates Vite React TypeScript projects using the official template
- 📦 Zip packaging - Packages generated projects into downloadable zip files
- 🔧 Configuration support - Accepts JSON configuration (extensible for future customization)
- 🏥 Health monitoring - Includes health check endpoint
- 🧹 Automatic cleanup - Cleans up temporary files after processing
- Node.js >= 18.0.0
- npm >= 8.0.0
- Create the project structure:
mkdir vite-scaffolder-service
cd vite-scaffolder-service
mkdir src
-
Copy the files:
- Save the main server code as
src/server.ts
- Save the package.json file as
package.json
- Save the TypeScript config as
tsconfig.json
- Save the main server code as
-
Install dependencies:
npm install
# Run in development mode with auto-reload
npm run dev
# Or with nodemon for file watching
npm run dev:watch
# Build the project
npm run build
# Start the server
npm start
The server will start on port 3000 by default (configurable via PORT
environment variable).
GET /health
Response:
{
"status": "healthy",
"timestamp": "2025-01-31T12:00:00.000Z",
"service": "vite-scaffolder"
}
POST /generate
Content-Type: application/json
Request Body:
{
"projectName": "my-app",
"customOptions": {
"someConfig": "value"
}
}
Response:
- Content-Type:
application/zip
- Content-Disposition:
attachment; filename="my-react-ts-app.zip"
- Binary zip file containing the generated Vite React TypeScript project
# Health check
curl http://localhost:3000/health
# Generate project
curl -X POST http://localhost:3000/generate \
-H "Content-Type: application/json" \
-d '{"projectName": "my-app"}' \
--output my-react-ts-app.zip
// Generate and download project
const response = await fetch('http://localhost:3000/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
projectName: 'my-custom-app',
customOptions: {
theme: 'dark'
}
})
});
if (response.ok) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'my-react-ts-app.zip';
a.click();
}
vite-scaffolder-service/
├── src/
│ └── server.ts # Main server implementation
├── dist/ # Compiled JavaScript (generated)
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
- Startup Check: Verifies npm is installed and accessible
- Request Processing: Accepts JSON configuration via POST /generate
- Project Creation: Runs
npm create vite@latest my-react-ts-app -- --template react-ts
- Packaging: Creates a zip archive of the generated project
- Response: Streams the zip file back to the client
- Cleanup: Removes temporary files and directories
The service generates a standard Vite React TypeScript project with:
my-react-ts-app/
├── public/
├── src/
│ ├── assets/
│ ├── App.tsx
│ ├── App.css
│ ├── index.css
│ ├── main.tsx
│ └── vite-env.d.ts
├── index.html
├── package.json
├── tsconfig.json
├── tsconfig.node.json
└── vite.config.ts
The service includes comprehensive error handling:
- npm availability check on startup
- Process execution error handling
- File system operation error handling
- Automatic cleanup on errors
- Detailed error responses with request IDs
PORT
: Server port (default: 3000)
The service provides detailed console logging for:
- Startup checks
- Request processing
- Project generation steps
- Error conditions
- Cleanup operations
The configuration system is designed to be extensible. Future versions could support:
- Custom project names
- Different Vite templates
- Custom file modifications
- Environment-specific configurations
- Plugin installations
- Ensure Node.js and npm are properly installed
- Check that npm is in your system PATH
- Try running
npm --version
manually
- Check disk space in temp directory
- Verify network connectivity for package downloads
- Check npm registry accessibility
- Ensure sufficient disk space
- Check file permissions in temp directory