'Upgrade the version of nodejs to 5.12.0

I tried to install node.js by NVM in Ubuntu 16.04 server by following this link. And I got:

root@instance-15s8fbzx:/opt# nodejs --version
v4.2.6
root@instance-15s8fbzx:/opt# npm --version
5.3.0
root@instance-15s8fbzx:/opt# node --version
v8.4.0

Then, we I run a mean-stack project by sudo npm start, I got

class User {
^^^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Then, I saw this link, I think maybe because the nodejs version is not correct. I have another server with v5.12.0 as the version of nodejs, and the project worked well there.

Then, I tried to do

sudo npm install -g npm
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/8.4.0/bin/node /usr/bin/node

But the version of the nodejs is still 4.2.6. Does anyone know how to upgrade its version to 5.12.0?



Solution 1:[1]

After you have installed NVM and you have installed the necessary version of node, you select the node version as follows:

> nvm use v5.12.0

Solution 2:[2]

After upgrading to the Nodejs version, the following error occurred for the Laravel and VUE js packages I already had: 

PHP Fatal error: During inheritance of IteratorAggregate: Uncaught ErrorException: Return type of Symfony\Component\HttpFoundation\ParameterBag::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\xampp\htdocs\clerk\vendor\symfony\http-foundation\ParameterBag.php:210

To solve the issue, I did the following: 
  1. composer update
  2. npm update
  3. npm run dev
  4. php artisan serve

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Flippance
Solution 2 Javad Heidarpour