clean-express-prisma
is a production-ready Express boilerplate including a fresh setup of Prisma, Typescript, Prettier, Heroku and file-based routing from Express File Routing.
- File-based routing
- Preconfigured path aliases
- Security middlewares for production
- Cleanest possible project structure
Clone the repository or Use this template.
git clone https://github.com/matthiaaas/clean-electron-react.git YOUR-PROJECT-NAME
cd YOUR-PROJECT-NAME
yarn
Create a (PostgreSQL) database and add it's url to .env
.
DATABASE_URL=postgresql://...
Note: See Prisma Docs
and PostgreSQL Installation Guide (macOS) on how to get started.
Start a dev server on localhost:4000.
yarn dev
The template contains pre-configured Procfile and is ready to be deployed on Heroku out-of-the-box. For deployment on other platforms further configuration might be necessary.
(Not Recommended) Manually run build scripts for production
yarn build
yarn db:deploy
yarn start
Files inside your project's /routes
directory will get matched an url path automatically.
├── app.ts
├── routes
├── index.ts // index routes
├── posts
├── index.ts
└── :id.ts // dynamic params
└── users.ts
└── package.json
/routes/index.ts
→ //routes/posts/index.ts
→ /posts/routes/posts/:id.ts
→ /posts/:id/routes/users.ts
→ /users
Note: See express-file-routing
for more details on how to use file-based routing.
/routes/projects.ts
import prisma from "~/lib/prisma"
export const get = async (req, res) => {
const projects = await prisma.projects.findMany()
return res.json(projects)
}
export const post = async (req, res) => {
const { name } = req.body
const project = await prisma.project.create({
data: {
name
}
})
return res.json(project)
}