Here is the layout of the relevant folders in my current project:
- package.json
- develop
- server.js
- routes
- htmlRoutes.js
- controllers
- userControl.js
- views
- home.handlebars
- profile.handlebars
- layouts
- main.handlebars
The URL I'm trying to go to is: '/users/profile/:id'
- htmlRoutes.js is linked correctly to my server.js
- My htmlRoutes.js imports a function from userControl.js (in controllers)
- My userControls.js is where I have my code that's supposed to take the user to their profile.
Relevant lines of code:
- Server.js
app.use('/', require('./routes/htmlRoutes'))
app.engine('handlebars', exphbs({
layoutsDir: (path.join(__dirname, '/views/layouts')),
defaultLayout:'main'}
))
- htmlRoutes.js
const { takeUserToProfile } = require('../controllers/userControl')
// this one actually works
router.get('/', (req, res) => {
res.render(path.join(__dirname, '../views/home'))
})
router.get('/users/profile/:id', takeUserToProfile)
- userControl.js
// this one gives me an error
exports.takeUserToProfile = async (req, res) => {
const data = await User.findById(req.params.id)
res.render('profile', {
username: data.username,
firstName: data.firstName,
lastName: data.lastName
})
}
I tried many different things and all I get is an error like this:
Error: Failed to lookup view "profile" in views directory "C:\Users\User\Desktop\repoName\views"
Is there any way to tell my file that there's a 'develop' folder between my repoName and views?