gpt4 book ai didi

javascript - Node.js 应用程序类型错误 [ERR_INVALID_ARG_TYPE] : The "path" argument must be of type string. 收到类型对象

转载 作者:行者123 更新时间:2023-12-02 23:49:16 24 4
gpt4 key购买 nike

我正在尝试创建一个文件夹 view/circle,我将能够在其中渲染数组,但是当我执行 localhost:3001/views/circle 时,没有加载任何内容,而是在标题上收到错误... ...................................................... ...................................................... …………

//-------I added this part in the code as you can see bellow this code-------
//const path = require("path");

//app.set("views", path.join(__dirname, "views"));
//app.set("view engine", "ejs");
//---------------------------------------------------------------------------
const express = require('express')
const path = require("path");
const cors = require('cors')
const app = express()


// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");

app.use(express.static('public'))
app.use(cors())

const circles = [
{
id: 1,
name: 'Twitter',
image: 'img/twitter.jpg',
color: '#aa2b31',
size: 3
},
{
id: 2,
name: 'Facebook',
image: 'img/facebook.jpg',
color: '#63e184',
size: 1
},
{
id: 3,
name: 'Skype',
image: 'img/skype.png',
color: '#033d49',
size: 2
},
]



app.get('/', (req, res) => {
const help = `

`

res.send(help)
})

app.get('/circles', (req, res) => {
res.render(circles)
})

app.listen(3001, () => {
console.log('Server listening on port 3001')
})

module.exports = app;

最佳答案

在这种特殊情况下,这可能没有任何帮助,但可能对搜索此错误的人有帮助。我得到这个是因为我将路线放置的顺序不正确。我的 /:id 路径在到达预期位置之前捕获了 post 请求。

关于javascript - Node.js 应用程序类型错误 [ERR_INVALID_ARG_TYPE] : The "path" argument must be of type string. 收到类型对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55713218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com