I am trying to run the ‘Example Backend’ from the course ‘Setting Up Postman - Learn Express Routes’ as part of my path as a Back-End Engineer. However, when I try to access it in my browser, I get an error message that says, “Cannot GET /.” My node version is v16.19.0, and I have already installed npm and Espress. Has anyone else encountered this error?
package.json
{
"name": "example_backend",
"version": "1.0.0",
"description": "A simple backend server to test out API requests",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Codecademy",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.1",
"express": "^4.18.2",
"sqlite3": "^5.1.4"
}
}
Could you share the server code that’s running? It may be that there is no route set up for the / using GET, but that doesn’t necessarily mean that the rest of the server isn’t working as it should
Yep that’s why, you have the following routes set up:
GET /users
GET /users/:id
POST /users
When visiting the base localhost:4000 URL in the browser, you’re sending a GET request to /. But there’s no route defined for a GET request to /, which is why visiting the URL in the browser throws an error
The server is still running as it should, and any of the defined routes should work fine! Try visiting localhost:4000/users to test.