Javascript bring developers up to many concepts because JS always pregresses day by day. All of new things start from common knowedges but no everyone understand, someone even can not distinguish them.



node.js vs express.js

First of all, people frequently confuse between node.js and express.js. Node.js is runtime environment for executing JavaScript code outside of a browser. It's not a framework or programming language. Express.js is just framework build on node.js

That's the reason we can run js file with node terminal



NPM vs YARN

Second, people whether yarn and npm which is better and how they work. NPM ( Node package manager ) and YARN (Yet Another Resource Negotiator ) are package manager to manage libraries we install in Javascript, they also read package.json then install package in folder node_modules. Yarn came because it has clear ternimation and better performance. One defective thing is YARN need to install by npm while npm is available in Node.js If we start with new project, I suggest using yarn.



Install globally vs locally

Talking about install libraries, I want to bring up a concept, install global vs local in npm package. When developer install

npm install express

That means a package is installed locally, it is listed under the “dependencies” or “devDependencies” section in the package.json file. Files of express store in node_modules folder of project express only in current project which installed it. We can not use express in another package. Some time, —-save-dev is added for package only use to develop, not required in production like

npm install eslint — save-dev

About global scope, we can inspest where package store by npm root -g. When we install package globally, all codes can use package. However, I suggest we just install package intended to be run from the CLI like nestjs

npm i -g @nestjs/cli nest new project-name



NPX

Last thing people often mistaken is NPX (Node Package eXecute). With NPX, we can execute package without install it. The solution is NPX will create temporary folder in cache to store pacakge binaries. When execution is over, NPX will remove this folder. Of course, if package is existing in local or global, NPX will prefer use available folder instead.

The Iconic example exist in react document

Image

Steve Nguyen

© Steve CV. All rights reserved.
Design - TemplateFlip