我試圖在nodejs中執(zhí)行一個后端程序,我正在使用mongodb。我正在創(chuàng)建一個表單,其中只有兩個輸入字段:密碼和名稱。我沒有使用任何hbs或ejs,也沒有默認(rèn)引擎,但是我的vs代碼終端顯示
"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 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}`);
})