P.Nuzum P.Nuzum - 9 months ago 59
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.


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


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

Answer Source

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){

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