Skip to content

A basic template repository for Node JS (With Express JS and TypeScript) projects.

Notifications You must be signed in to change notification settings

snigdho611/node-express-template

Repository files navigation

Node Express Template (With TS)

Description:

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:

  1. @prisma/client
  2. cors
  3. dotenv
  4. express
  5. express-validator
  6. multer
  7. tsconfig-paths
  8. winston
The following are the development packages:
  1. @eslint/js
  2. @types/eslint__js
  3. @types/bcryptjs
  4. @types/cors
  5. @types/express
  6. @types/multer
  7. @types/node
  8. nodemon
  9. prisma
  10. typescript
  11. typescript-eslint
  12. ts-node-dev
  13. 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,
        }

Setup:

  1. Clone the repository at first:
  2. git clone [email protected]:snigdho611/node-template.git
  3. Navigate into that directory:
  4. cd node-template
  5. Switch to the correct branch. The branch for the postgres setup is called `typescript-postgres`:
  6. , and the command will be:
    git checkout typescript-postgres
  7. Install the necessary packages:
  8. npm install
  9. 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:
  10. DATABASE_URL=postgres://[username]:[password]@localhost:5432/to_do_list
  11. Generate the prisma client:
  12. npx prisma generate
  13. Run the migration with this command:
  14. npx prisma migrate dev
  15. 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:
  16. PORT=8000
  17. Run the project in dev using:
  18. npm run dev

Update as of 25th December, 2024 includes logger with color coded logs

Author: Snigdho Dip Howlader

About

A basic template repository for Node JS (With Express JS and TypeScript) projects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published