- Consists of javascript samples, basic to advanced concepts
-
bluebird - Promisifies the calls, usage
eg:var Promise = require('bluebird'); var fs = Promise.promisifyAll(require('fs')); // Check the example in promise-sample.js
-
consider
pm2module for process or cluster related solutions -
multerpackage for uploading files -
run
babelwith latest JS features using,nodemon// Install babel plugins $ npm install babel-cli babel-preset-env --save-dev // add the script to package.json scripts: { "babel-node": "babel-node --presets=/*a*/ --ignore='foo|bar|baz'" } $ nodemon --exec npm run babel-node -- path/to/script.js (or) $ nodemon --exec babel-node /path/file.js -
Add
.babelrcfile to add the@babel/preset-envwith this entry{ "presets": ["@babel/preset-env"] } -
Use
esmpackage to use ES Modules in nodejs app in commandlinenode -r esm <filename.js> -
ES Modules can be used in
node 13.7(experimental feature) by specifying"type": "module"inpackage.jsonand while importing give the file withextensionimport {test} from './test-module.js -
Pass file name as a param to npm script as follows, Making use of
esmpackage to compile with ESM modules given filescripts: { "start":"func() { nodemon -r esm $1; }; func", }
-
pass the param as follows
npm run start <full-path>ornpm run start -- <file-name> -
To get the code coverage for all files using jest, update test script in package.json as,
"jest --watchAll --coverage"