clone the repo by writing this command
git clone https://github.com/mohamedhoss123/express-template.git --depth 1 yourProjectName
after that go to package.json
file and change package name
then wrote pnpm install
- after cloning the repo rename file
.example.env
to.env
then add the database connection string - run the command
pnpm run db:generate
thenpnpm run db:migrate
to init db orpnpm run db:push
if you don't want to make migratin
use the command pnpm run dev
to run the project .
important : controllers must prefix with *.controller.ts
controller are auto loaded by the loadControllers
helper and invoked in main.ts
file be aware that this aprouch won't make tsx auto reload so you can manually reload it by pressing enter
key on the keyboard , you don't need to restart the command just press enter
on the watch terminal session
this template provide some useful helpers :
zodFactory
the zodFactory
helpers allows you to add a zod schema and it will automaticlly return a middleware with your schema to validate it for example
zod schema :
export const CreateUser = z.object({
username: z.string(),
email: z.string().email(),
password: z.string()
})
your controller:
@UseBefore(ValidationFactory(CreateUser))
@Post("/register")
@HttpCode(201)
async register(@Body() body: TCreateUser) {
await AuthService.createUser(body);
return "ok"
}