Unexpected token ILLEGAL using node javascript

nodejs npm
syntaxerror: unexpected token illegal mongodb

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);
    });
});

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.

This issue tracker is for bugs and issues found within Node.js core. For more general support questions like this one, please file an issue in our  To add to what @starkwang said: If you've installed a newer version of Node.js but it is not the version you get when you type node -v, then you'll need to change things so that the old version of node isn't appearing in your PATH before the new version.


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".

during node install on Windows 7 OS node install C:\Users\Documents\GitHub\​aat\adapt_authoring\lib\usermanager.js:139 var tenantName  It was a simple button that when clicked fired some JavaScript. Uncaught SyntaxError: Unexpected token ILLEGAL I saw articles talking about hidden characters, UTF16 encoding all kinds of stuff.


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

C:\Adapt Authoring Tool\adapt_authoring>node server SyntaxError: Unexpected token ILLEGAL _extensions..js (module.js:474:10) The important takeaway is that JavaScript’s parser expects tokens and symbols in a particular order, with relevant values or variables in between. Often, Unexpected Token errors are just due to an accidental typo, but to help avoid these, it is quite beneficial to use a code editor that provides some form of auto-completion. This is particularly useful when forming basic logical blocks or writing out method argument lists, since the editor will often automatically provide the necessary


getting the following /root/node_modules/tmi.js/lib/client.js:119 this.log.warn(`​Could not parse message with no prefix:\n${ ^ SyntaxError: Unexpected token ILLEGAL at Module. Which version of Node.js are you running? The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo. Skip to main content


The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. Some errors in JavaScript are hard to find out and this is one of them, 'Unexpected Token ILLEGAL' message on your console can make you go crazy and re-check the code but if you didn't solve the problem read the post.


SyntaxError: Unexpected token ILLEGAL at exports. _compile (module.js:460:​26) error: Forever detected script exited with code: 1 error:  Youre totally right.It seems like its a bug in Meteor instead of node-mysql.It shouldnt try to require this file in the firste place.Ill have an look into it.