P.Nuzum P.Nuzum - 1 month ago 10
Node.js Question

Express Router "Cannot GET ..." on browser screen

I'm trying to set up a router.get that is in another folder rather than /routes.
When I direct browser to this route, I get "Cannot GET /auth_box" on browser screen.
Either you can't so this, or I'm doing something dumb.

app.js:

var index = require('./routes/index');
var auth_box = require('./public/js/download_cs');
app.use('/', index);
app.use('/auth_box', auth_box);


download_cd.js:

var express = require('express');
var app = express();
var router = express.Router();
router.get('/auth_box', function(req, res){
console.log("/auth_box");
});
module.exports = router;

Answer

You have the url /auth_box twice.
When you use a route, the first argument is the default path for that route, so right now the correct URL would be /auth_box/auth_box

In your route, just do

router.get('/', function(req, res){
  console.log("/auth_box");
});

As you've already set /auth_box in app.use('/auth_box', auth_box);

Comments