Akhilesh Kumar Akhilesh Kumar - 1 year ago 110
Node.js Question

I'm using let keyword in for loop gives SyntaxError: Unexpected identifier

I'm using let keyword in for loop as following

for(let methd1 in servUrl){
let methd=methd1;
for(let pth1 in servUrl[methd]) {
let pth=pth1;
app[methd](pth, servUrl[methd][pth]);

which gives me following error

for(let methd1 in servUrl){
SyntaxError: Unexpected identifier

Answer Source

Can you please make sure, if you are using the supported version of node.

To know the node version you may run the following command:

$ node --version

Node older versions do not support the let syntax or EcmaScript6 all features.

I also had experienced the similar issue and upgrading my node to latest solved my issue.

To upgrade node you can run the followings:

$ sudo npm cache clean -f
$ sudo npm install -g n
$ sudo n stable
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download