节点 index.js 返回 "Unexpected token >"
node index.js returning "Unexpected token >"
我做了javascript有一段时间了,决定开始node.js。
我是运行node.js,表达在raspberry pi(但我怀疑这是问题的根源)。
我正在用 socket.io 制作一个聊天应用程序,说明中说要创建一个 package.json:
{
"name": "socket-chat-example",
"version": "0.0.1",
"description": "my first socket.io app",
"dependencies": {}
}
然后我运行命令npm install express@4
。
之后,我做了一个index.js
文件。
这是代码。
const app = require('express')();
const http = require('http').createServer(app);
app.get('/', (req, res) => {
res.send('<h1>Hello world</h1>');
});
http.listen(3000, () => {
console.log('listening on *:3000');
});
错误代码:
/home/pi/Desktop/index.js:4
app.get('/', (req, res) => {
SyntaxEror: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
谢谢!
我做了javascript有一段时间了,决定开始node.js。
我是运行node.js,表达在raspberry pi(但我怀疑这是问题的根源)。
我正在用 socket.io 制作一个聊天应用程序,说明中说要创建一个 package.json:
{
"name": "socket-chat-example",
"version": "0.0.1",
"description": "my first socket.io app",
"dependencies": {}
}
然后我运行命令npm install express@4
。
之后,我做了一个index.js
文件。
这是代码。
const app = require('express')();
const http = require('http').createServer(app);
app.get('/', (req, res) => {
res.send('<h1>Hello world</h1>');
});
http.listen(3000, () => {
console.log('listening on *:3000');
});
错误代码:
/home/pi/Desktop/index.js:4
app.get('/', (req, res) => {
SyntaxEror: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
谢谢!