-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
31 lines (23 loc) · 879 Bytes
/
server.js
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
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import connectDB from './config/db.js';
import tweetRoutes from './routes/tweetRoutes.js';
import colors from 'colors';
import path from 'path';
import { notFound, errorHandler } from './middleware/errorMiddleware.js';
dotenv.config();
connectDB();
const moduleURL = new URL(import.meta.url);
const __dirname = path.dirname(moduleURL.pathname);
const PORT = process.env.PORT || 8080;
const app = express()
app.use(express.json());
app.use(cors());
app.use('/tweets', tweetRoutes);
app.get('/', (req, res) => {
res.send(`Welcome to The Tweeter API! Go to https://github.com/ingridclaire/the-tweeter-api/blob/master/README.md for documentation on using this API`)
})
app.use(notFound);
app.use(errorHandler);
app.listen(PORT, console.log(`server running on port ${PORT}`.bold.yellow));