1

I have not used Node before, but have setup an Apache localhost.

In my directory, I have index.js which reads

var app = require('express')();
var http = require('http').Server(app);

app.get('/', function(req, res){
  res.send('<h1>Hello world</h1>');
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});

and a package.json which requires Express.js.

In the command line, I cd into the workspace and run node index.js. But it does not open the server and instead throws this error. enter image description here

What needs to be done to produce a local server listening on port 3000? Node version is 6.7.0, express is 4.15.2. Running on Windows 10.

Naltroc
  • 989
  • 1
  • 14
  • 34
  • 1
    Take a look at this: https://stackoverflow.com/questions/12719859/no-visible-cause-for-unexpected-token-illegal – Rob M. Apr 24 '17 at 23:12

1 Answers1

3

It looks like your text editor may be inserting some unsupported (non-UTF8) BOM in your index.js. Try adjusting your text editor preferences/settings to either instead include a UTF-8 BOM or remove BOMs entirely (node will read the javascript file as UTF-8 no matter what).

mscdex
  • 104,356
  • 15
  • 192
  • 153