首页 > 解决方案 > 如何使用 JavaScript 连接 variavél no vs code?

问题描述

我是 NodeJs 的新手,我正在使用带有 JavaScript 的 VS 代码。但他不承认这种争执。

当我通过路由时: http://localhost:3000/user/2 而不是返回 2 它返回: "message": "GET API ${id}"

const express = require('express')
const server = express()

server.get('/user/:id', (req, res) => {

const id = req.params.id

return res.json({message: 'GET API ${id}'}) ----my problema is here
})

server.listen(3000)

标签: javascriptnode.jsvisual-studio-code

解决方案


你必须使用这个字符来cancat `(反引号)

return res.json({message: `GET API ${id}`})

推荐阅读