# nodejs - best practices
# misc links
sindresorhus/awesome-nodejs
- github.com
ryanmcdermott/clean-code-javascript
- github.com
i0natan/nodebestpractices
- github.com
Node.js Best Practices : Matt Goldspink 20160829
- Start all projects with
npm init
- Setup
.npmrc
- Add scripts to your
package.json
- Use environment variables
- Use a style guide
- Embrace async
- Handle errors
- Ensure your app automatically restarts
- Cluster your app to improve performance and reliability
- Require all your dependencies up front
- Use a logging library to increase errors visibility
- Use Helmet if you’re writing a web app
- Monitor your applications
- Test your code
Node.js Best Practices - How to Become a Better Developer in 2017 : blog.risingstack.com
# switching node version between projects
# articles
nvm vs n! - .gitignore - 20170522
How I manage multiple Node.js versions - steelbrain.me - 20160719
The Best Way to Install Node.js - yoember.com - 20180929
# tooling comparison
Taken from stackoverflow answer from nvm
maintainer
The most-used version managers for node are without a doubt http://nvm.sh, https://www.npmjs.com/package/nave, and https://www.npmjs.com/package/n.
nvm
is for modifying individual shell sessions to use the version you want.nave
is for launching subshells with the version you want loaded. n is for switching a single system-wide version of node.
nvm
uses a.nvmrc
file, which like.ruby-version
, contains the version-ish string X you'd normally couple withnvm use X
ornvm install X
.nvm use
ornvm install
by itself will locate the.nvmrc
file, as will simply sourcingnvm
upon opening a new shell.It appears
nave
supports a.naverc
file, but I'm not too familiar with its usage.
n
doesn't appear to support any such config, but as it's system-wide, it doesn't really make as much sense to do so.
avn
supports.node-version
and attempts to provide automatic version switching by hooking intocd
, afternvm
decided that was too invasive a behavior to include.
# nvm
NVM Automatic Switching : gist
# n
Node.js version management: no subshells, no profile setup, no convoluted API, just simple.
# usage
Super easy but system wide.
List installed version
n
Output :
0.8.14
ο 0.8.17
0.9.6
2
3
Change the active version by selecting the line and hit space bar.
Install desired node version with n <version>
ex n 10.2.1
.
# issues
Possible issue with npm
, any npm
command will output this :
npm WARN lifecycle npm is using /home/<HOME_DIR>/n/bin/node but there is no node binary in the current PATH. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
Fixed by adding a .npmrc file in the project root dir containing :
scripts-prepend-node-path=true
# node
package with npx
using a node package inside package.json
cf tweet
# app structure
- DRY sur le config projet (eslint, code quality, etc ...)
- automatisation des conventions
- 12 factors
- logging
- swagger
- unit / functionnal testing
- CI (circle & jenkins)
- deploy
- health checking
- métriques métiers
Advanced Node.js Project Structure Tutorial - 20180508
# microservices
The Best Node.js & Microservices Articles we Ever Wrote - blog.risingstack.com - 20180516
Node.js - File System - www.tutorialspoint.com
- Synchronous vs Asynchronous
- Open a File
- Flags
- Get File Information
- Writing a File
- Reading a File
- Closing a File
- Truncate a File
- Delete a File
- Create a Directory
- Read a Directory
- Remove a Directory