I started setting up a node app but it prompt me this
syntax error near unexpected token `('
'/app.js: line 1: `var http = require("http");
this is my code for app.js
var http = require("http");
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, 'localhost');
console.log('Server running at http://localhost:8080/');
can anyone help me in this
Why are you typing in bash?
Please try to type "$ node" first and then you should see: Welcome to Node.js v14 (or any version that you have installed).
This is probably because you are running your script as if it is a bash script. You have two options
$ node your_pgm.js
#!/path/to/node
to the beginning of your program (it must be the very first 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.