so this is my server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
const sequelize = require('./db');
const userRoutes = require('./routes/users');
app.use('./users', userRoutes);
sequelize.sync({ force: false })
.then(() => {
console.log('Database & tables created!');
})
.catch(err => {
console.error('Unable to sync the database: ', err);
});
app.use(bodyParser.json());
app.listen(port, () => {
console.log(`SERVER IS RUNNING ON PORT ${port}`);
});
module.exports = {app, sequelize};
my application starts when I run node server.js on terminal but when I try to get the users list it returns an html page which says ” Cannot GET /users “.
this is my users.js file and none of methods works.
const express = require('express');
const router = express.Router();
const User = require('../models/User');
//Read All Users
router.get('/', async (req, res) => {
try {
const users = await User.findAll();
res.status(200).json(users);
} catch (error) {
res.status(400).json( { error: error.message });
}
});
module.exports = router;
Sorry I had to cut a lot of my codes I just put Read All Users because the main code was so long.