javascript - 如何使用 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)
解决方案
你必须使用这个字符来cancat `(反引号)
return res.json({message: `GET API ${id}`})
推荐阅读
- php - json没有被php接收
- javascript - React-snapshot 使用 create-react-app 和 serve 在所有路由上预渲染 index.html
- powershell - 如何使用 powershell 更改任务触发器?
- c - Atmel:中断后无法转主
- firebase - 在从云 Firestore 数据库中检索主图像之前,如何在 CircleAvatar 中放置虚拟图像?
- ios - Xcode IDE 布局未与 Main.storyboard 一起显示 ViewController 连接
- php - 降低子数组键并组合项目
- java - 使用gradle在eclipse中导入spring boot应用
- mysql - 如果不存在字符模式,MySQL 仅替换单个字符
- excel - 值之间的 Excel 查找