A basic template repository for Node JS (With Express JS and TypeScript) projects. Has some basic functionalities already set up, such as REST APIs and file upload handler.
The project is fully set up with Express JS & TypeScript
The project uses a static json file to handle data, but a database connection functionality (Mongo DB) has been implemented and left commented out for those who may want to use it.
Packages that are required to run this include:
The following are the development packages:- @eslint/js
- @types/eslint__js
- @types/bcryptjs
- @types/cors
- @types/express
- @types/multer
- @types/node
- nodemon
- prisma
- typescript
- typescript-eslint
- ts-node-dev
- tsc-alias
Source folder architecture:
src/
config/
controller/
middleware/
model/
routes/
service/
utils/
app.ts
The following routes are already set up for demo purposes:
1. route: "/posts/all"
method: "GET",
2. route: "/posts/detail/:id"
method: "GET"
3. route: "/posts/create"
method: "POST",
payload: "body",
body: {
title: string,
content: string,
user_id: number
}
4. route: "/posts/file"
method: "POST",
payload: "form-data",
data:{
my-file: file,
}
- Clone the repository at first:
- Navigate into that directory:
- Switch to the correct branch. The branch for the postgres setup is called `typescript-postgres`: , and the command will be:
- Install the necessary packages:
- In the .env file, You will need to set the connection string for your database. This is the connection string for a postgresql database running on localhost, and the database is named to_do_list. Please take note of the username and password as it will be different for each user:
- Generate the prisma client:
- Run the migration with this command:
- In the .env file. If you want a port of your choice to run the project on, set it up inside a .env file. This is the env value for port if you want to run it on port 8000:
- Run the project in dev using:
git clone [email protected]:snigdho611/node-template.git
cd node-template
git checkout typescript-postgres
npm install
DATABASE_URL=postgres://[username]:[password]@localhost:5432/to_do_list
npx prisma generate
npx prisma migrate dev
PORT=8000
npm run dev
Update as of 25th December, 2024 includes logger with color coded logs
Author: Snigdho Dip Howlader