简体   繁体   中英

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.

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 .

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. It can be used for debugging, testing, or just trying things out. Here is one good how-to-use-nodejs-repl

Whereas, the command line is used to run the node command like node server.js .

You run node server.js in command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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