【发布时间】:2018-03-15 05:48:34
【问题描述】:
无法让它与节点一起运行
const express = require('express')
const app = express()
app.use(express.static('public')) //adds content of public folder
app.get('/', function (req, res){
res.sendFile('/views/index.html', {root: __dirname})
})
app.listen(1337, function (){
console.log('lab5-server.js listening on 1337')
})
昨天运行得很完美,现在却不行了。 .html 部分也有问题,它不会显示我分配的图像。请注意,我遗漏了图像源代码下方的大部分内容,这个问题没有必要。
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1> <center> Welcome to Matt's Page </center></h1>
<center> <img src = "images/AlgorithmofSuccess.jpg"/> </center>
有谁知道我哪里出错了,为什么终端在 javascript 部分返回“意外令牌”?
【问题讨论】:
-
如果仅此而已,
__dirname未定义 -
“为什么终端在 javascript 部分返回“意外的令牌””——不是
-
@johnSmith — nodejs.org/api/modules.html#modules_dirname
-
我们可以改进一下这个标题吗?
-
确定你想让我怎么改?
标签: javascript html node.js