-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (25 loc) · 677 Bytes
/
index.js
File metadata and controls
31 lines (25 loc) · 677 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
import express from 'express';
import taskRoutes from './routes/tasks.js';
import 'dotenv/config';
import { connectDB } from './db/connect.js';
import { errorHandler } from './middleware/errorHandler.js';
const PORT = process.env.PORT ?? 3000;
const app = express();
const start = async (connectionString) => {
try {
await connectDB(connectionString);
app.listen(PORT, () => {
console.log(`Listening ${PORT}`);
});
} catch (e) {
console.log(e);
}
};
start(process.env.MONGO_URI);
// Middleware
app.use(express.json());
app.use('/api/v1/tasks', taskRoutes);
app.use(errorHandler);
app.get('/', (req, res) => {
res.send('Hello World!!!');
});