-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
32 lines (26 loc) · 994 Bytes
/
server.ts
File metadata and controls
32 lines (26 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @file Server file
*/
import express, {Request, Response} from 'express';
import UserController from "./controllers/UserController";
import TuitController from "./controllers/TuitController";
import mongoose from "mongoose";
// connect to the database
const DB_USERNAME = process.env.DB_USERNAME;
const DB_PASSWORD = process.env.DB_PASSWORD;
const connectionString = `mongodb+srv://adarsh:Adarsh=97@softwareeng.ueqhd.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`;
mongoose.connect(
connectionString
// "mongodb://localhost:27017/Tuiter"
);
// create RESTful Web service API
const app = express();
app.use(express.json());
app.get('/', (req: Request, res: Response) =>
res.send('Welcome!'));
app.get('/add/:a/:b', (req: Request, res: Response) =>
res.send(req.params.a + req.params.b));
const userController = UserController.getInstance(app);
const tuitController = TuitController.getInstance(app);
const PORT = 4000;
app.listen(process.env.PORT || PORT);