2017-04-17 50 views
-2

我创建了一个简单明确的NodeJS应用:无法运行一个简单的ES6应用的NodeJS

const express = require("express"); 
const app = express(); 
app.set("views", path.join(__dirname, "views")); 
app.listen(3000, => (req, res) { 
    res.sendFile("index.html") 
}) 

它抛出一个异常:

app.listen(3000, => (req, res) { 
       ^^ 
SyntaxError: Unexpected token => 
+0

难道不是相反吗?我的意思是'(req,res)=> {...}'。 –

回答

0

arrow功能应该是这样的

app.listen(3000,(req, res) => 

或没有arrow,它会是这样的

app.listen(3000, function (req,res) { 
    console.log('Example app listening on port 3000!'); 
}) 
+0

现在它说“ReferenceError:path is not defined” – Dorion

+0

@Dorion那是因为你从未定义'path'。 –

+0

@Dorion:这意味着代码中还有一个问题需要解决。有关错误消息的内容不清楚吗? –

相关问题