NodeJS: Difference between revisions

No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 4: Line 4:


==Installation==
==Installation==
===Windows===
Just download the latest LTS release from [https://nodejs.org/en/ the Node.js website]
===Linux===
===Linux===
Using the [https://github.com/nvm-sh/nvm Node Version Manager (nvm)] is recommended. This does not require sudo as nvm is installed in your home directory.
Using the [https://github.com/nvm-sh/nvm Node Version Manager (nvm)] is recommended.<br>
You should never use sudo when using npm. Doing so could lead to permission issues.
This installs nvm in your home directory.
You should never use sudo when using nvm or npm.  
Doing so could lead to permission issues.
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
# Reload .bashrc
source ~/.bashrc
source ~/.bashrc
nvm install --lts node
nvm install --lts node
nvm install-latest-npm
nvm install-latest-npm
</syntaxhighlight>
===Windows===
You can [https://nodejs.org/en/ install node directly] or use [https://github.com/coreybutler/nvm-windows nvm-windows].<br>
Note that nvm-windows is not a port of nvm.
<syntaxhighlight lang="bash">
choco install nvm
nvm install lts
</syntaxhighlight>
</syntaxhighlight>


Line 80: Line 86:
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
</syntaxhighlight>
</syntaxhighlight>


===Running other processes===
===Running other processes===
Line 137: Line 142:
[https://www.npmjs.com/package/argparse argparse]
[https://www.npmjs.com/package/argparse argparse]


This is a port of python's argparse. However, it does not support configuration files. I usually use this snippet to parse configuration files:
This is a port of python's argparse. However, it does not support configuration files.  
{{hidden | Example |
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
const parser = new ArgumentParser({
const parser = new ArgumentParser({
Line 164: Line 170:
})();
})();
</syntaxhighlight>
</syntaxhighlight>
}}


===node-worker-threads-pool===
===node-worker-threads-pool===
[https://www.npmjs.com/package/node-worker-threads-pool Link]   
[https://www.npmjs.com/package/node-worker-threads-pool Link]   
A cool thread pool implementation.
A cool thread pool implementation.