this is the server.js code
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const cors = require('cors')
const cookieParser = require('cookie-parser')
const app = express()
app.use(express.json())
app.use(cors())
app.use(cookieParser())
//Routes
app.use('api', require('./routes/authRouter'))
const URI = process.env.MONGODB_URL
mongoose.connect(URI, {
useCreateIndex: true,
useFindAndModify: false,
useNewUrlParser: true,
useUnifiedTopology: true
}, err => {
if(err);
console.log('Connected to mongodb')
})
const port = process.env.PORT || 5000
app.listen(port, ()=> {
console.log('server up and running', port)
})
authRouter code
const router = require('express').Router()
const authCtrl = require('../controllers/authCtrl')
router.post('/register', authCtrl.register)
router.post('/login', authCtrl.login)
router.post('/logout', authCtrl.logout)
router.post('/refresh_token', authCtrl.generateAccessToken)
module.exports = router
authCntrl code
const Users = require('../models/userModel')
const bcrypt = require('bcrypt')
const jwt = require('jsonwebtoken')
const authCtrl = {
register: async (req,res) => {
try {
const { fullname, username, email, password, gender } = req.body
console.log(req.body);
res.json({msg: 'registered'})
} catch (err) {
return res.status(500).json({msg: err.message})
}
},
login: async (req,res) => {
try {
} catch (err) {
return res.status(500).json({msg: err.message})
}
},
logout: async (req,res) => {
try {
} catch (err) {
return res.status(500).json({msg: err.message})
}
},
generateAccessToken: async (req,res) => {
try {
} catch (err) {
return res.status(500).json({msg: err.message})
}
}
}
module.exports = authCtrl
auth router code
const router = require('express').Router()
const authCtrl = require('../controllers/authCtrl')
router.post('/register', authCtrl.register)
router.post('/login', authCtrl.login)
router.post('/logout', authCtrl.logout)
router.post('/refresh_token', authCtrl.generateAccessToken)
module.exports = router
package.json
{
"name": "web",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"dev": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.11.13"
},
"devDependencies": {
"nodemon": "^2.0.7"
}
}
the thing is that everything seems like its okay but when i open localhost in the browser it doest show
and in postman too
in the terminal it says
server up and running 5000
Connected to mongodb
could be that the dependencies that im using are a bit outdated but im trying to follow a tutorial that was made in January of this year, so i dont want to change the dependencies or update them.