javascript - 此代码中未读取 Javascript 变量
问题描述
const express = require('express');
const app = express();
app.get('/',(req, res) => {
res.status(200).send('Hello from the server');
});
const port = 3000;
app.listen(port, () => {
console.log('App running on port ${ port }...');
});
当我在终端中运行此代码时,它显示为
[nodemon] starting `node app.js`
App running on port ${port}...
解决方案
您只能将字符串插值与模板字符串一起使用。
console.log(`App running on port ${ port }...`);
推荐阅读
- javascript - 使用 JS/TS 从二进制字符串创建和下载 PDF 文件
- c# - 后台启动的任务在第一次遇到等待后未完成/终止
- c# - 每 20 毫秒发送一个音频包
- r - 防止 r-markdown 展开代码/功能
- angular - Chart.js / ng2-charts:悬停时的活动图表元素
- visualvm - 如何从 VisualVM 的 CPU 采样器结果中复制多行?
- javascript - SyntaxError: Unexpected token '/' whilecompileing ejs but works if I remove <% include ./src/myTemplate.ejs%>
- powershell - Powershell 条件
- mysql - 将 int 结果转换为 MySQL 中的字符串选项
- node.js - 将 mongo vars 发送到 Mail