javascript - Just want to set up a simple server using node
为情所困
为情所困 2017-05-16 13:22:09
0
7
355

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

为情所困
为情所困

reply all(7)
某草草

Try it node D:nodeserver.js

漂亮男人

Isn’t it necessary to start the service? node server.js

洪涛

You can enter directlyD:node,然后按shift键右击选择cmd窗口打开,直接运行node server.jsThat’s it

漂亮男人

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

大家讲道理

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

大家讲道理

Method 1:

Method 2:

洪涛

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template