I run this with node app.js
I have already performed npm init and npm i express ejs –save
const express =require(express);
const app=express();
const path= require('path');
app.set('views',path.join(__dirname,'views'));
app.set('view engine','ejs');
app.get('/questions',(res,req)=>{
let questions = [
{title:"what is node.js?", user: "John", votes: "10"},
{title:"what is Express.js?", user: "Sam", votes: "15"},
{title:"what is Mongodb?", user: "Gaurav", votes: "115"}
]
res.render('index',{questions:questions});
})
app.listen(8080,()=>{
console.log('Server started on port 8080');
});
Still getting this error:
at Object.<anonymous> (C:UsersjangrDocumentsPRacticeExpressJSEjsloopsapp.js:1:24)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49
New contributor
Gaurav Jangra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.