Currently, I am following the steps outlined in this guide:
Despite conducting extensive research, I am facing difficulty in getting it to work as expected.
Here is the folder structure I am working with: https://i.sstatic.net/jCEdO.png
Below is a snippet of my code:
// app.js
var express = require('express');
var app = express();
var port = 3000;
app.use(express.static('public'));
app.listen(port, function(){
console.log('Server is running on port:', port);
})
app.get('/', function(req, res){
res.send('Hello Express');
});
app.set('view engine', 'ejs');
var itemRouter = express.Router();
app.use('/items', itemRouter);
itemRouter.route('/').get(function (req, res) {
res.render('items');
});
itemRouter.route('/single').get(function (req, res) {
res.render('singleItem');
});
Upon running the code, I encountered the following error:
Error: Failed to lookup view "items" in views directory "C:\Users\Karol\views"
at Function.render (C:\Users\Karol\node_modules\express\lib\application.js:580:17)
at ServerResponse.render (C:\Users\Karol\node_modules\express\lib\response.js:1008:7)
at C:\Users\Karol\Desktop\CB\app.js:27:7
at Layer.handle [as handle_request] (C:\Users\Karol\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Karol\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\Karol\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\Karol\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\Karol\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\Karol\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\Karol\node_modules\express\lib\router\index.js:275:10)
When accessing localhost:port/items
, the above error message is displayed (replace 'port' with the actual port number).