Hi everyone, smart people, I am a beginner here and I have a problem with my code while working on the server side. I really need help.
const express = require('express'); const app = express(); app.set = ('view engine', 'ejs'); app.use(express.static('public')) app.use(express.urlencoded()); app.get('/', async (req, res)=>{ res.render('index.ejs') }) app.get('/addstock', (req, res)=>{ res.render('addstock.ejs') }) app.listen(8080, ()=>{ console.log('server is currently on port 8080') })
The following is the response I got:
C:\Users\go\Desktop\New folder\WEB project\kemstac\node_modules\express\lib\application.js:439 return boolean(this.set(set)); ^
Type error: this.set is not a function in Function.enabled (C:\Users\go\Desktop\New Folder\WEB Project\kemstac\node_modules\express\lib\application.js:439:23) in Function.lazyrouter (C:\Users\go\Desktop\New Folder\WEB Project\kemstac\node_modules\express\lib\application.js:147:27) in Function.use (C:\Users\go\Desktop\New Folder\WEB Project\kemstac\node_modules\express\lib\application.js:221:8) in object. (C:\Users\go\Desktop\New folder\WEB project\kemstac\app.js:16:5) at Module._compile(node:internal/modules/cjs/loader:1255:14) in Module._extensions..js (node:internal/modules/cjs/loader:1309:10) at Module.load(node:internal/modules/cjs/loader:1113:32) in Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) In node:internal/main/run_main_module:23:47
Node.js v20.2.0 [nodemon] Application crash - waiting for file changes before starting...
The problem is with the line where you set the view engine in Express.
The corrected code looks like this: