-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (24 loc) · 810 Bytes
/
index.js
File metadata and controls
30 lines (24 loc) · 810 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
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import usersRoutes from './routes/users.js';
import authRoutes from './routes/auth.js';
const app = express();
const PORT = process.env.PORT || 3000;
const CONNECTION_URL = 'mongodb://localhost:27017/corsoapinode';
app.use(express.json());
app.use(cors());
app.use('/users', usersRoutes); //http://localhost:3000/users
app.use('/auth', authRoutes); //http://localhost:3000/users
app.get('/', (req, res) => res.send('Benvenuto nella homepage'));
mongoose
.connect(CONNECTION_URL)
.then(() => {
app.listen(PORT, () => {
console.log(`server running on port: ${PORT}`);
});
})
.catch((error) => console.error(error));
app.listen(PORT, () => {
console.log(`server running on port: ${PORT}`);
});