-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (33 loc) · 982 Bytes
/
index.js
File metadata and controls
40 lines (33 loc) · 982 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
33
34
35
36
37
38
39
40
// Require the framework and instantiate it
const fastify = require('fastify')({
logger: true
})
// // Declare a route
// fastify.get('/', async (request, reply) => {
// return { hello: 'world' }
// })
const routes = require('./routes');
const swagger = require('./config/swagger');
fastify.register(require('fastify-swagger'), swagger.options);
routes.forEach((route, index) => {
fastify.route(route)
})
// Run the server!
const start = async () => {
try {
await fastify.listen(3000)
fastify.swagger()
fastify.log.info(`listening on ${fastify.server.address().port}`)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
// Require external modules
start()
// Require external modules
const mongoose = require('mongoose')
// Connect to DB
mongoose.connect('mongodb://localhost/mycargarage')
.then(() => console.log('MongoDB connected…'))
.catch(err => console.log(err))