[Fixed] Not Found 404 NotFoundError: Not Found Node JS and Express


I’m trying to access my routes /api and /api/superheroes, but i’m getting this error when I do that.

Not Found
NotFoundError: Not Found
    at C:\Users\mikae\Desktop\Project\node-express-swig-mongo\app.js:27:8
    at Layer.handle [as handle_request] (C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:275:10)
    at C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:635:15
    at next (C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:260:14)
    at Function.handle (C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\mikae\Desktop\Project\node-express-swig-mongo\node_modules\express\lib\router\index.js:47:12)


var api = require('./routes/api.js');
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/api', api);

// catch 404 and forward to error handler
app.use(function(req, res, next) {

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);

module.exports = app;


var express = require('express');
var router = express.Router();

router.get('/superheros', function(req, res) {
  res.send('Just a test');

module.exports = router;

I’m following a tutorial and I already saw from scratch again and I didn’t found the solution. I just want to access the routes that I’ve created to continue the lesson. Someone can help me? What should I do?


You’ve got a typo: it says /superheros (heros, not heroes) in api.js. Also, under /api, you’re mounting a Router instance that has exactly one route defined: /superheros. There’s no / route in the Router that you pass to:

app.use('/api', api);

And so, there is no handler for /api + /.

Leave a Reply

(*) Required, Your email will not be published