Reputation: 119
I'm trying to create a folder view/circle where Im gonna be able to render the array but when I do localhost:3001/views/circle is not loading anything, instead I get the error on the title....................................................................................................................
//-------I added this part in the code as you can see bellow this code-------
//const path = require("path");
//app.set("views", path.join(__dirname, "views"));
//app.set("view engine", "ejs");
//---------------------------------------------------------------------------
const express = require('express')
const path = require("path");
const cors = require('cors')
const app = express()
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.static('public'))
app.use(cors())
const circles = [
{
id: 1,
name: 'Twitter',
image: 'img/twitter.jpg',
color: '#aa2b31',
size: 3
},
{
id: 2,
name: 'Facebook',
image: 'img/facebook.jpg',
color: '#63e184',
size: 1
},
{
id: 3,
name: 'Skype',
image: 'img/skype.png',
color: '#033d49',
size: 2
},
]
app.get('/', (req, res) => {
const help = `
`
res.send(help)
})
app.get('/circles', (req, res) => {
res.render(circles)
})
app.listen(3001, () => {
console.log('Server listening on port 3001')
})
module.exports = app;
Upvotes: 1
Views: 9014
Reputation: 105
I got this because I had placed the routes in incorrect order. My /:id
path caught the post request before it got to where it was supposed to.
Upvotes: 2
Reputation: 1
Replace set
with use
:
from
app.set("views", path.join(__dirname, "views"));
to
app.use("views", path.join(__dirname, "views"));
Upvotes: 0