I have been working on executing a backend program in Node.js using MongoDB. I have created a form with two input fields for password and name. I am not utilizing any HBS or EJS and my VS Code terminal is displaying the following error:
No default engine was specified and no extension was provided. at new View (C:\Users\LENOVO\Desktop\adin\backend\node_modules\express\lib\view.js:61:11) at Function.render (C:\Users\LENOVO\Desktop\adin\backend\node_modules\express\lib\application.js:587:12) at ServerResponse.render (C:\Users\LENOVO\Desktop\adin\backend\node_modules\express\lib\response.js:1039:7) at C:\Users\LENOVO\Desktop\adin\backend\src\app.js:46:25 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
app.js
const static_path =path.join(__dirname,"../public");
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(static_path));
app.get("/", (req,res) => {
res.render("index");
});
app.get("/index", (req,res) => {
res.render("index");
})
//create a new user in the database
app.post("/index", async (req,res) => {
try{
const indexSchema = new Index({
name: req.body.name,
password: req.body.password
});
const indexed = await indexSchema.save();
res.status(201).render("index");
} catch(error) {
res.status(400).send(error);
console.log(error);
}
})
app.listen(port, () => {
console.log(`server is running at port no ${port}`);
})