Node.js + Express + TypeScript boilerplate for building REST APIs.
If you're interested in using MongoDB, check out the MongoDB branch.
-
Clone the Repository: Begin by cloning the repository to your local machine:
git clone [email protected]:dazfz/backend-express-ts.git cd backend-express-ts
-
Install Dependencies: Install the required dependencies using npm:
npm install
-
Run Development Server: Start the development server:
npm run dev
-
Production Build: To create a production build, run:
npm run tsc
This will generate a production build in the
build
directory. -
Start Production Server: Start the production server:
npm start
- express: Backend framework.
- cors: Cross-origin resource sharing. Required if the frontend and backend run on different ports.
- dotenv: Loads environment variables from a
.env
file.
- ts-node: TypeScript execution environment for Node.js. Not strictly required, but useful for running TypeScript code directly.
- typescript: TypeScript language support.
- ts-node-dev: Auto-reloading for TypeScript files, similar to
nodemon
. - eslint: Linting tool for identifying and enforcing code style. Not required.
- @typescript-eslint/eslint-plugin: TypeScript-specific ESLint rules.
- @typescript-eslint/parser: Parser that allows ESLint to lint TypeScript code.
- morgan: HTTP request logger middleware. Useful for development and debugging, not required in all cases.
- @types/express: Type definitions for Express.js.
- @types/cors: Type definitions for the cors package.
- @types/morgan: Type definitions for the morgan logger.
-
build: This directory contains the production build of the backend.
-
dist: Here, you can find the production build of the frontend.
-
requests: This directory includes request files that are used for testing the API with the Visual Studio Code (VSCode)
Rest Client
extension. -
src:
- models: Contains the models related to the objects.
- routes: Defines the API routes for the objects.
- services: Houses the object-related services.
- tests: This directory is intended for storing test-related files.
- utils: Provides utility modules such as configurations, middleware, and more.