'Error - Can not see text in visual code when doing a request
I have a simple basic node.js entry file by the name of index.js and the below code for this file is as following:
const express = require("express");
const expressApp = require("./express-app/test.js");
const { PORT } = require("./config");
const { databaseConnection } = require("./database");
const StartServer = async () => {
const app = express();
//database connection
await databaseConnection();
expressApp(app);
app
.listen(PORT, () => console.log(`Customer is listening on port ${PORT}`))
.on("error", (err) => {
console.log(err);
process.exit();
});
};
StartServer();
and also have a file by the name of test.js with the following code as below:
const express = require("express");
const cors = require("cors");
module.exports = (app) => {
app.use(express.json({ limit: "1mb" }));
app.use(express.urlencoded({ extended: true, limit: "1mb" }));
app.use(cors);
app.use(express.static(__dirname + "/public"));
// Listen to Events //
app.use("/app-events", (req, res, next) => {
console.log("Had reached");
});
};
When I do a request with url http://localhost:portnumber/app-events, I can not see "Had reached" in the console.
I'm wondering what am I doing wrong??
Solution 1:[1]
I think it should be app.get(...) instead of app.use(..)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Edmilson da Conceição |
