Node.js - Overview
What is Node.js
$ node > var a = 1; undefined > a + 1 2
Node doesn’t run any of your application code in parallel
Pros and Cons
- event-driven, non-blocking I/O, fast and lightweight.
- npm, the package manager.
- awesome libraries.
- not supporting multi-threading.
- not suitable for heavy computing problems.
- no strict checking, could result in runtime problems.
When to use nodejs
Data-driven, I/O-driven, event-driven, and non-blocking applications benefit the best from a Node.js implementation.
- Data-intensive programs are focus on retrieving and storing data,
- I/O-intensive programs focus on interacting with external resources.
Web servers are a perfect use case that benefits from Node’s inherent features.
When not to use Node.js
Node a bad choice for CPU-intensive programs.
Check Versions And Upgrade
Check version of node:
$ node -v vX.X.X $ nvm current
Check version of npm:
$ npm -v X.X.X
Install latest LTS version
$ nvm install --lts
Get Project Folder
Development and Deployment
nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.
$ sudo npm install -g nodemon
$ sudo npm install -g pm2
Start production, with max memory:
$ NODE_ENV=production pm2 -f start app.js --max-memory-restart 200M
$ pm2 monit