Skip to main content

Create your first project

This guide walks you through creating a complete Node.js API with Express, PostgreSQL, and Drizzle ORM, including JWT authentication.
1

Run the CLI

Open your terminal and run:
npm create node-blueprint
The CLI will start and display a welcome message.
2

Enter project name

When prompted, enter your project name:
◆  What is the name of your project?
│  my-blog-api
The CLI creates a directory with this name in your current location. If the directory already exists, you’ll be asked whether to overwrite it.
3

Select framework

Choose your preferred Node.js framework:
◆  Which Node.js framework would you like to use?
│  ● Express
Currently, Express is the primary option with Fastify support in development.
4

Select database

Choose your database:
◆  Which database would you like to use?
│  ○ MongoDB
│  ○ MySQL  
│  ● PostgreSQL
Use arrow keys to navigate and press Enter to select.
5

Select ORM

Choose your ORM based on the database you selected:
◆  Which ORM/ODM would you like to use?
│  ● Drizzle
│  ○ Prisma
If you selected MongoDB, Mongoose is automatically selected as it’s the recommended ODM for MongoDB.
6

Configure authentication

Choose whether to include authentication:
◆  Would you like to include one of the following authentication?
│  ● Basic JWT authentication
│  ○ None
JWT auth includes login, register, token refresh, and password hashing with bcrypt.
7

Add optional features

Select additional features (use Space to select, Enter to continue):
◆  What additional features would you like to include?
│  ◻ Include Docker setup
Docker setup includes a Dockerfile and docker-compose.yml with your selected database pre-configured.
8

Wait for generation

The CLI creates your project structure, generates files, and installs dependencies:
✔ Creating project files...
✔ Package.json created
✔ Installing dependencies...
✔ Git initialized
This typically takes 30-60 seconds depending on your internet speed.

What was generated?

After successful creation, you’ll see a success message with next steps:
┌  🎉 Project created successfully!

│  Next steps:
│  1. cd my-blog-api
│  2. npm run dev

│  Your app is available at:
│  The server is available on port 8000

│  Database commands:
│  - Generate migration: npm run db:generate
│  - Apply migration: npm run db:migrate

│  Thank you for using node-blueprint. If you find it useful,
│  please give it a star on GitHub!
│  https://github.com/yogendrarana/node-blueprint

Project structure

Your generated project includes:
my-blog-api/
├── src/
│   ├── config/          # Configuration files (database, CORS, logger)
│   ├── controllers/     # Request handlers
│   ├── db/             # Database schema and migrations (Drizzle)
│   │   ├── schema/
│   │   │   ├── user-schema.ts
│   │   │   └── token-schema.ts
│   │   ├── index.ts
│   │   ├── schema.ts
│   │   └── seed.ts
│   ├── enums/          # TypeScript enums
│   ├── middlewares/    # Express middleware (CORS, error handling, helmet)
│   ├── routes/         # Route definitions
│   ├── services/       # Business logic
│   ├── types/          # TypeScript type definitions
│   ├── utils/          # Utility functions
│   ├── validations/    # Request validation schemas
│   ├── views/          # EJS templates
│   ├── app.ts          # Express app configuration
│   ├── router.ts       # Main router
│   └── server.ts       # Server entry point
├── .env                # Environment variables
├── .gitignore
├── drizzle.config.ts   # Drizzle ORM configuration
├── package.json
├── README.md
└── tsconfig.json
If you selected Docker, you’ll also see Dockerfile, docker-compose.yml, and .dockerignore files in the root directory.

Configure your environment

Before running the app, set up your environment variables:
1

Open the .env file

cd my-blog-api
The .env file is already created with sensible defaults.
2

Update database connection

Edit the database URL to match your setup:
DATABASE_URL="postgresql://postgres:password@localhost:5432/mydb"
3

Configure JWT secrets (if using auth)

Update the JWT secrets (important for production):
JWT_ACCESS_SECRET="your-access-secret-here"
JWT_REFRESH_SECRET="your-refresh-secret-here"
Never commit real secrets to version control. The generated .gitignore already excludes .env files.
4

Set the port (optional)

The default port is 8000, but you can change it:
PORT=3000

Set up the database

Generated projects include database schema and migration tools:
1

Ensure database exists

Create your database if it doesn’t exist:
PostgreSQL
createdb mydb
Or connect to PostgreSQL and run:
CREATE DATABASE mydb;
2

Generate migration

Generate the migration files from your schema:
npm run db:generate
This creates migration files in src/db/migrations/ based on your schema definitions in src/db/schema/.
3

Apply migration

Run the migration to create tables:
npm run db:migrate
Your database now has the users and tokens tables (if you selected JWT auth).
4

Seed data (optional)

The project includes a seed file at src/db/seed.ts. Customize it and run:
npm run db:seed

Run your application

Start the development server:
npm run dev
You should see:
[INFO] Server is running on port 8000
[INFO] Database connected successfully
The dev server uses tsx for hot-reloading. Changes to your TypeScript files automatically restart the server.

Test the API

Your application includes several pre-built endpoints:

Health check

Verify the server is running:
curl http://localhost:8000/api/health
Response:
{
  "status": "ok",
  "timestamp": "2026-03-03T12:34:56.789Z"
}

Authentication endpoints (if JWT auth enabled)

Create a new user:
curl -X POST http://localhost:8000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "[email protected]",
    "password": "SecurePassword123!"
  }'
Response:
{
  "success": true,
  "message": "User registered successfully",
  "data": {
    "user": {
      "id": "1",
      "name": "John Doe",
      "email": "[email protected]"
    },
    "accessToken": "eyJhbGciOiJIUzI1NiIs...",
    "refreshToken": "eyJhbGciOiJIUzI1NiIs..."
  }
}

User endpoints

Get all users (example endpoint):
curl http://localhost:8000/api/users
In production, you should add authentication middleware to protect sensitive endpoints. The generated code includes examples you can extend.

Explore the code

Now that your app is running, explore the generated code:

Routes

Check src/routes/ to see how endpoints are defined. Each route file maps HTTP methods to controller functions.

Controllers

Open src/controllers/ to see request handling logic. Controllers process requests and call services.

Database schema

For Drizzle: src/db/schema/
For Prisma: prisma/schema.prisma
For Mongoose: src/models/

Middleware

Review src/middlewares/ for CORS, error handling, and security (Helmet) configurations.

Next steps

1

Add new endpoints

Create new route files in src/routes/, controllers in src/controllers/, and wire them together in src/router.ts.
2

Extend the schema

Add new database models or modify existing ones in your schema files, then generate and run migrations.
3

Add validation

Use the patterns in src/validations/ to add request validation for your new endpoints.
4

Deploy

When ready, build for production:
npm run build
npm start
Or use the included Docker setup for containerized deployment.
The generated README.md in your project includes additional details about the specific stack you selected. Check it for more information!

Troubleshooting

If you see connection errors:
  1. Verify your database is running (check with psql, mysql, or mongosh)
  2. Confirm the DATABASE_URL in .env matches your database credentials
  3. Ensure the database exists (create it if needed)
  4. Check firewall settings if using a remote database
If port 8000 is already taken:
  1. Change the PORT in your .env file
  2. Or find and kill the process using port 8000:
# Find the process
lsof -ti:8000

# Kill it
kill -9 $(lsof -ti:8000)
For Drizzle migration issues:
  1. Check that drizzle.config.ts has the correct database URL
  2. Ensure your database user has sufficient permissions
  3. Try dropping and recreating your database (development only!)
For Prisma:
  1. Delete the prisma/migrations/ folder
  2. Run npx prisma migrate dev --name init to start fresh
If you see type errors:
  1. Run npm install to ensure all dependencies are installed
  2. For Prisma: Run npx prisma generate to update the Prisma Client
  3. Restart your IDE’s TypeScript server
  4. Check that tsconfig.json hasn’t been modified

What’s next?

You’ve successfully created and run your first Node Blueprint project! Here are some ideas for what to build:
  • Blog API: Add posts, comments, and categories
  • E-commerce backend: Products, carts, and orders
  • Task management: Projects, tasks, and team collaboration
  • Social network: Users, posts, likes, and follows
Happy coding!

Build docs developers (and LLMs) love