Sunday, 23 April 2017

Error when running nodejs

I am trying to set up nodejs with atom on ubuntu 16.10. I followed the steps given in this link. And edited the ~/.atom/config.cson file to

runner:
  scopes:
    js: "nodejs"

as given in the link

This is my server.js file

#!/usr/bin/env nodejs
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/');

It gives this error when I try to run it.

./server.js: line 3: syntax error near unexpected token `('
./server.js: line 3: `var http = require('http');'

Is it not able to see nodejs?



via Ashwin

No comments:

Post a Comment