0

I am trying to execute a command using node JavaScript, but I am getting "Uncaught SyntaxError: Unexpected token ILLEGAL" in my javascript.Its on line 1.

var express = require('express');
var mongodb = require('mongodb');
var app = express();
var MongoClient = require('mongodb').MongoClient;
var db;
var port = process.env.PORT || 8080;

MongoClient.connect(mongo_host, function(err, database) {
    if(err) throw err;
    db = database;
    app.listen(port, function () {
        console.log('listening port' + port);
    });
});

app.get('/', function (req, res) {
    res.json({ message: 'Bienvenue Azure!' });
});

app.get('/plante', function (req, res) {
    db.collection("plante").find().toArray(function(err, users) {
        res.send(users);
    });
});

NB: mongo_host is the Git repository url to connect with azure

Then it is showing the following error:

SyntaxError: Unexpected token ILLEGAL
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:138:18)
    at node.js:974:3
Peter Pan
  • 23,476
  • 4
  • 25
  • 43
spoonatte
  • 35
  • 1
  • 7

3 Answers3

3

Your semicolons aren't standard semicolons. They are \u037e (Greek Question Mark). Try switching them back to standard semicolons and then running the code.

Someone has been reading twitter.

dvlsg
  • 5,378
  • 2
  • 29
  • 34
0

As @dvlsg said, it's a syntax error which caused by some illegal symbols like .

There was a similiar SO thread which be helpful for you, please see No visible cause for "Unexpected token ILLEGAL".

Community
  • 1
  • 1
Peter Pan
  • 23,476
  • 4
  • 25
  • 43
0

I solved this error by updating my node version in the Azure web app service to the latest (10.6.0 in my case). It had been balking at the lines containing ES6. One way to change that is with an environment variable. You can change it in 'Application settings' in your app's portal. Change WEBSITE_NODE_DEFAULT_VERSION

ELH
  • 1
  • 2