Node.js tips and tricks: Difference between revisions
Jump to navigation
Jump to search
(Created page with " == Install latest Node.js<ref>https://deb.nodesource.com/</ref> == <syntaxhighlight lang="bash"> #Install Node.js 20.x LTS $curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - $sudo apt-get install -y nodejs </syntaxhighlight> == References == <references />") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Update nodejs package.json <syntaxhighlight lang="bash"> | |||
# Install npm-check-updates globally | |||
$ npm i -g npm-check-updates | |||
# Inside of nodejs project folder where package.json is located | |||
$ ncu -u | |||
Upgrading /opt/imp/home/prj/rim/package.json | |||
[====================] 39/39 100% | |||
async ^2.6.3 → ^3.2.6 | |||
canvas-gauges ^2.1.5 → ^2.1.7 | |||
cheerio ^1.0.0-rc.2 → ^1.0.0 | |||
cookie-parser ^1.4.4 → ^1.4.7 | |||
.... | |||
# Run npm install to install new versions. | |||
$ npm install | |||
</syntaxhighlight> | |||
== Install NVM == | |||
<syntaxhighlight lang="bash"> | |||
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash | |||
source ~/.bashrc | |||
# List up node version | |||
nvm list-remote | |||
# Install specific version | |||
nvm install 18.0.0 | |||
# List of installed versions | |||
nvm ls | |||
# Change version | |||
nvm use 16.15.0 | |||
# Update npm | |||
npm install -g npm@latest | |||
</syntaxhighlight> | |||
== Install latest Node.js<ref>https://deb.nodesource.com/</ref> == | == Install latest Node.js<ref>https://deb.nodesource.com/</ref> == | ||
Line 6: | Line 46: | ||
$sudo apt-get install -y nodejs | $sudo apt-get install -y nodejs | ||
</syntaxhighlight> | |||
== Change node version == | |||
<syntaxhighlight lang="bash"> | |||
# Get available version list using nvm | |||
$ nvm ls | |||
v4.9.1 | |||
v6.17.1 | |||
v8.8.1 | |||
v8.9.4 | |||
v8.17.0 | |||
v10.24.1 | |||
-> v14.15.1 | |||
v16.20.0 | |||
v18.16.0 | |||
system | |||
default -> v14.15.1 | |||
# change version v18 temporary and check the changing version | |||
$ nvm use v18.16.0 | |||
$ nvm ls | |||
v4.9.1 | |||
v6.17.1 | |||
v8.8.1 | |||
v8.9.4 | |||
v8.17.0 | |||
v10.24.1 | |||
v14.15.1 | |||
v16.20.0 | |||
-> v18.16.0 | |||
system | |||
default -> v14.15.1 << default version will not be changed | |||
# change default version v18 sytemwide | |||
$ nvm alias default v18 | |||
default -> v18 (-> v18.16.0) | |||
$ nvm ls | |||
v4.9.1 | |||
v6.17.1 | |||
v8.8.1 | |||
v8.9.4 | |||
v8.17.0 | |||
v10.24.1 | |||
v14.15.1 | |||
v16.20.0 | |||
-> v18.16.0 | |||
system | |||
default -> v18 (-> v18.16.0) << default version has been changed | |||
node -> stable (-> v18.16.0) (default) | |||
stable -> 18.16 (-> v18.16.0) (default) | |||
# Install new version of node | |||
$ nvm install <version you want to> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== References == | == References == | ||
<references /> | <references /> |
Latest revision as of 09:17, 23 October 2024
Update nodejs package.json
# Install npm-check-updates globally
$ npm i -g npm-check-updates
# Inside of nodejs project folder where package.json is located
$ ncu -u
Upgrading /opt/imp/home/prj/rim/package.json
[====================] 39/39 100%
async ^2.6.3 → ^3.2.6
canvas-gauges ^2.1.5 → ^2.1.7
cheerio ^1.0.0-rc.2 → ^1.0.0
cookie-parser ^1.4.4 → ^1.4.7
....
# Run npm install to install new versions.
$ npm install
Install NVM
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
# List up node version
nvm list-remote
# Install specific version
nvm install 18.0.0
# List of installed versions
nvm ls
# Change version
nvm use 16.15.0
# Update npm
npm install -g npm@latest
Install latest Node.js[1]
#Install Node.js 20.x LTS
$curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
$sudo apt-get install -y nodejs
Change node version
# Get available version list using nvm
$ nvm ls
v4.9.1
v6.17.1
v8.8.1
v8.9.4
v8.17.0
v10.24.1
-> v14.15.1
v16.20.0
v18.16.0
system
default -> v14.15.1
# change version v18 temporary and check the changing version
$ nvm use v18.16.0
$ nvm ls
v4.9.1
v6.17.1
v8.8.1
v8.9.4
v8.17.0
v10.24.1
v14.15.1
v16.20.0
-> v18.16.0
system
default -> v14.15.1 << default version will not be changed
# change default version v18 sytemwide
$ nvm alias default v18
default -> v18 (-> v18.16.0)
$ nvm ls
v4.9.1
v6.17.1
v8.8.1
v8.9.4
v8.17.0
v10.24.1
v14.15.1
v16.20.0
-> v18.16.0
system
default -> v18 (-> v18.16.0) << default version has been changed
node -> stable (-> v18.16.0) (default)
stable -> 18.16 (-> v18.16.0) (default)
# Install new version of node
$ nvm install <version you want to>