First of all, my nodejs installation path is under C:\Program Files\nodejs
,
My project is built under the D:\node
folder
project There is a server.js file used to create a server. The content is as follows:
var http = require('http');//使用 require 指令来载入 http 模块
http.createServer(function (request, response) {
// 发送 HTTP 头部
// HTTP 状态值: 200 : OK
// 内容类型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 发送响应数据 "Hello World"
response.end('Hello World\n');
}).listen(8888);
// 终端打印如下信息
console.log('Server running at http://localhost:8888/');
How to start this server? ? ?
I entered in cmdC:\Program Files\nodejs\node D:\node\server.js
The prompt reported an error: SyntaxError: Invalid or unexpected token
I tried many methods None of them work, please help me find out where the problem is
PHP中文网2017-05-16 13:24:09
You can enter directlyD:node
,然后按shift
键右击选择cmd
窗口打开,直接运行node server.js
That’s it
漂亮男人2017-05-16 13:24:09
After running it, there is no problem with the code of the question. Is there something wrong with the node program? Run it and try something else
大家讲道理2017-05-16 13:24:09
The SyntaxError: Invalid or unexpected token error is a syntax error. Check whether there are unmatched brackets, redundant or missing punctuation marks. Or use Chinese punctuation marks
PHP中文网2017-05-16 13:24:09
When I see an error report, I just panic and don’t know to read the error message carefully. I just shout to God, God, come and help me. I can’t do it. What should I do if the program reports an error?
No one is born a master, others are just more careful and patient than you.
Even the syntax error cannot be solved by itself. Segmentfault is really unskilled.