Variable showing as ‘undefined’ when I try to hit the route

I thought I had properly set up my CRUD for two different models (venues & artists) — venues works fine but when I try to hit my ‘artists/index’, I receive the error ‘Artists is not defined’.

As far as I can tell, I only need two things:

  1. Artist variable defined (7th row from top)
  2. A get request in the app.js (route syntax is listed in the very last grouping below)

I’ve confirmed my post requests work by validating there’s artist data in the database using the terminal, but I can’t get them to pull through the route.

Can you help me understand what I’m missing? It’s driving me nuts!

const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const ejsMate = require('ejs-mate');
const methodOverride = require('method-override');
const Venue = require('./models/venue');
const Artist = require('./models/artist');

const dbUrl = process.env.DB_URL || 'mongodb://localhost:27017/data-base';

mongoose.connect(dbUrl, {
    useNewUrlParser: true,
    useCreateIndex: true,
    useUnifiedTopology: true,
    useFindAndModify: false

const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", () => {
    console.log("Database connected");

const app = express();

app.engine('ejs', ejsMate);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'))

app.use(express.urlencoded({ extended: true }));

app.get('/', (req, res) => {

app.get('/venues', async (req, res) => {
    const venues = await Venue.find({});
    res.render('venues/index', { venues })

app.get('/artists', async (req, res) => {
    const artists = await Artist.find({});
    res.render('artists/index', { artists })

I’m receiving the following error and you can see artists/index.ejs on my github

ReferenceError: /Users/chaseschlachter/mtapp/views/artists/index.ejs:8
 <%  for (let artist of Artists) {%>
  <li><a href="/artists/<%= artist._id %>"><%= %>/a></li>
     <% } %> 

Artists is not defined


Probably you missed to include artists in res.render('artists/index', artists ).

As you need to specify in more detail your codebase.