I'm trying to separate app and server. It is running properly but when tried to hit "app.get('/')" api it is giving Error: connect ECONNREFUSED 127.0.0.1:3000 in Postman even after changing required settings.
In ./routes/users.js
const express = require('express');
const router = express.Router();
const { registerUser, getUserList, login, updateUser, deleteUser } = require('../controller/users');
const validateToken = require('../middlewares/auth');
router.post('/login', login);
router.post('/registeruser', registerUser);
router.get('/list', validateToken, getUserList);
router.patch('/update/:userId', validateToken, updateUser);
router.delete('/delete', validateToken, deleteUser);
module.exports = router;
In connect.js (connectDByour text
)
const mongoose = require('mongoose');
const color = require('colorette');
const connectDB = (url) => {
try {
return mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
} catch (error) {
console.log(color.bgRed(error));
}
};
module.exports = connectDB;
In server.js
const app = require('./app');
const http = require('http')
const port = process.env.PORT || 3000;
const connectDB = require("./database/connect");
const server = http.createServer(app);
const color = require('colorette');
//