-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (24 loc) · 793 Bytes
/
server.js
File metadata and controls
31 lines (24 loc) · 793 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
// server.js
import express from 'express';
import mongoose from 'mongoose';
// Import routers
import shortUrlRouter from './controllers/shortUrlController.js';
const app = express();
// Connect to DB
mongoose
.connect('mongodb://localhost/urlShortener', {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log('Connected to MongoDB'))
.catch((err) => console.log('MongoDB connection error:', err));
// Use imported routes
app.use('/', shortUrlRouter);
// Set up EJS as the view engine
app.set('view engine', 'ejs');
// Middleware for parsing URL-encoded data
app.use(express.urlencoded({ extended: false }));
// Start the server
app.listen(process.env.PORT || 5000, () => {
console.log(`Server running on port ${process.env.PORT || 5000}`);
});