This project sets up an Express backend using TypeScript and uses a JSON file as a database for storing submissions.
- Node.js and npm installed
- Visual Studio Code
-express-ts-app
- ├── src
- │ ├── routes
- │ │ └── submission.ts
- │ ├── db.json
- │ └── index.ts
- ├── tsconfig.json
- ├── package.json
- └── nodemon.json
- Open VSCode and create a new folder for your project:
mkdir express-ts-app cd express-ts-app
- Initialize a new Node.js project:
npm init -y
- Install the necessary dependencies:
npm install express body-parser npm install -D typescript @types/express @types/node ts-node nodemon
- Initialize a TypeScript configuration file:
npx tsc --init
- Update your 'tsconfig.json':
Open the tsconfig.json file and replace its content with the following configuration: { "compilerOptions": { "target": "ES6", "module": "commonjs", "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true }, "include": ["src/**/*.ts"], "exclude": ["node_modules"] }
###Step 2: Create Project Files
-
Create the project structure:
mkdir -p src/routes touch src/routes/submission.ts src/db.json src/index.ts touch nodemon.json
-
Setup Nodemon for Development:
Create nodemon.json in the root directory: { "watch": ["src"], "ext": "ts", "exec": "ts-node ./src/index.ts" }
-
Create db.json in the src folder:
Create a db.json file inside the src folder with the following initial content: { "submissions": [] }
-
**adjust the 'submission.ts' code on your os. **
-
**adjust the 'index.ts' code on your os. **
-
Start your server:
npx nodemon