This is a project template for building a REST API using Typescript with Node.js and Express.
The project has the following file structure:
src/app.ts
: Entry point of the application. Creates an instance of the express app and sets up middleware and routes.src/controllers/index.ts
: Exports a classIndexController
which has a methodgetIndex
that handles the root route of the application.src/routes/index.ts
: Exports a functionsetRoutes
which sets up the routes for the application. It uses theIndexController
to handle the root route.src/models/index.ts
: Exports a classUser
which represents a user in the application. It has propertiesid
,name
, andemail
.src/middleware/index.ts
: Exports a middleware functionlogger
which logs the incoming requests to the console.src/config/index.ts
: Exports a constantPORT
which specifies the port number for the application to listen on.src/types/index.ts
: Exports interfacesRequest
andResponse
which extend the interfaces from theexpress
library. It also exports an interfaceUser
which extends theUser
class fromsrc/models/index.ts
.tsconfig.json
: Configuration file for TypeScript. Specifies the compiler options and the files to include in the compilation.package.json
: Configuration file for npm. Lists the dependencies and scripts for the project.README.md
: This file.
- Clone the repository.
- Install dependencies with
npm install
. - Build the project with
npm run build
. - Start the server with
npm start
.
GET /
: Returns a welcome message.GET /users
: Returns a list of all users.GET /users/:id
: Returns the user with the specified ID.POST /users
: Creates a new user.PUT /users/:id
: Updates the user with the specified ID.DELETE /users/:id
: Deletes the user with the specified ID.
This project is licensed under the MIT License. See the LICENSE file for details.