-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (25 loc) · 723 Bytes
/
server.js
File metadata and controls
32 lines (25 loc) · 723 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
import express from 'express';
import postsRouter from './routes/posts.js';
import connectDB from './config/db.js';
import cors from 'cors';
import compression from 'compression';
const app = express();
const port = process.env.PORT || 5050;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(compression());
// Connect to database
connectDB();
// API route
app.use('/api/posts', postsRouter);
app.get('/', (req, res) => {
res.send('Yay!! Backend of wanderlust app is now accessible ');
});
app.get('/conn', (req, res) => {
res.send(process.env.MONGODB_URI);
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
export default app;