簡體   English   中英

當我嘗試運行我的節點 app.js 時,我的命令行出錯

[英]Error in my command line when i tried to run my node app.js

當我嘗試從我的服務器運行 node app.js 時。 它帶來了以下錯誤:

Router.use() 需要一個中間件 function 但得到一個字符串
在 Function.use (C:\Users\BLUE HOST\Desktop\todolist-v1\node_modules\express\lib\router\index.js:464:13)
在 Function。 (C:\Users\BLUE HOST\Desktop\todolist-v1\node_modules\express\lib\application.js:220:21)
在 Array.forEach ()
在 Function.use (C:\Users\BLUE HOST\Desktop\todolist-v1\node_modules\express\lib\application.js:217:7)
在 Object。 (C:\Users\BLUE HOST\Desktop\todolist-v1\app.js:6:5)
在 Module._compile (node:internal/modules/cjs/loader:1101:14)
在 Object.Module._extensions..js (節點:internal/modules/cjs/loader:1153:10)
在 Module.load (node:internal/modules/cjs/loader:981:32)
在 Function.Module._load (node:internal/modules/cjs/loader:822:12)
在 Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

這是我的 app.js 文件:

const express = require("express");
const app = express();
app.use(express.urlencoded({extended: true}));
app.use("view engine", "ejs");

app.get("/",function(req,res) {
var today = new Date();
var currentDay = today.getDay();
var day = "";

if (currentDay === 6 || currentDay === 0) {
day = "weekend";
} else{
day = "weekday";
 }
 res.render("list", { kindOfDay: day });
});

app.listen(3000, function() {
console.log("Listening on port 3000");
});

This is my list.ejs file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To do List</title>
</head>
<body>
<h1><%= kindOfDay %></h1>
</body>

app.use("view engine", "ejs")行,所需的第二個參數是Argument of type 'string' is not assignable to parameter of type 'Application'

讓我們試試:

app.set('view engine', 'ejs');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM