首页 > 解决方案 > 此代码中未读取 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}...

标签: javascriptnode.jsportatom-editornodemon

解决方案


您只能将字符串插值与模板字符串一起使用。

console.log(`App running on port ${ port }...`);

推荐阅读