简体   繁体   English

节点js无法与SyntaxError一起使用:意外的标识符

[英]node js not working with SyntaxError: Unexpected identifier

So, started learning node.js and tried the most basic thing in the world: A "Hello World" from the server. 因此,开始学习node.js并尝试了世界上最基本的东西:来自服务器的“ Hello World”。

the code is the following (copied from an actual book): 代码如下(从实际书籍中复制):

var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(8888);

I hit the node.js executable, type node server.js and gives the famous SyntaxError: Unexpected identifier . 我点击了node.js可执行文件,输入node server.js并给出了著名的SyntaxError: Unexpected identifier

Tried looking for similar questions but couldn't find something that would help something as simple as what I'm trying to accomplish. 试图寻找类似的问题,但找不到可以帮助我实现目标的简单问题。

The node REPL aka node shell, the REPL provides a way to interactively run JavaScript and see the results. node REPL又称为节点外壳,REPL提供了一种以交互方式运行JavaScript并查看结果的方法。 It can be used for debugging, testing, or just trying things out. 它可以用于调试,测试或只是尝试。 Here is one good how-to-use-nodejs-repl 这是一个很好的如何使用nodejs-repl

Whereas, the command line is used to run the node command like node server.js . 而命令行用于运行诸如node server.js类的node命令。

You run node server.js in command line. 您在命令行中运行node server.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM