index.js
const app = express()
const port = 5000
const mongoose = require('mongoose')
mongoose.connect('mongodb+srv://hijw01:1q2w3e4r5t@boilerplate.kvilj.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', {
}).then(() => console.log('MongoDB Connected...'))
.catch(err => console.log(err))
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
package.json
{
"name": "boiler-plate",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jeongwon",
"license": "ISC",
"dependencies": {
"express": "^4.17.2",
"mongoose": "^6.1.7"
}
}
1) 터미널

2) localhost:5000
