I created a connection node mysql using express. so i have this error that i cannot understand where is wrong
"Cannot GET /" into my localhost http://localhost:8080/
and in the google error (white the F12) he show me this :
-"GET http://localhost:8080/ 404 (Not Found)"
-"DevTools failed to load SourceMap: Could not load content for chrome-extension://hnmpcagpplmpfojmgmnngilcnanddlhb/browser-polyfill.min.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME"
ther i have the organization of my files;
-controllers
user.controller.js
-routes
user.routes.js
server.js
this is my server.js file
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
//const dbConfig = require("./config/db.config.js");
//à voir apres
//var routes = require('./routes/indexRoutes');
//configuration de express server
//parse requests of content-type - application/json
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors(corsOptions));
app.use(bodyParser.json());
var corsOptions = {
origin: "http://localhost:8081"
};
// parse requests of content-type
app.use(bodyParser.urlencoded({ extended: true }));
//connection à la bdd
const db = require("./models");
//on démarre le serveur
const PORT = process.env.PORT || 8080;
app.listen(PORT,()=>{
console.log("Express serveur est opérationnelle sur le port : "+PORT);
});
require("./routes/user.routes")(app);
user.controller.js
const mysqlConnection = require("../models");
// afficher tout les users
exports.findAllUser = (req, res) => {
mysqlConnection.query('SELECT * From user', (err, rows, fields)=>{
if(!err){
console.log(rows);
res.send(rows);
}
else{
console.log(err);
}
})
}
user.routes.js
module.exports = userRoutes => {
const userController = require("../controllers/user.controller.js");
var router = require("express").Router();
// Create a new Tutorial
router.get("/", userController.findAllUser);
userRoutes.use('/api/tutorials', router);
};
What are the reasons for this.
Thanks in advance...
You didn't parse the router to express.
In user.routes.js
try
userRoutes.use('/api/tutorials', router);
and the api url should be http://localhost:8080/api/tutorials
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.