This is a mini project about basic NodeJs.
- OS: Ubuntu 18
- Install NodeJs on Linux
$ sudo apt-get install nodejs
(1)
To check version of Nodejs:$ node -v
When you run command (1) that is also install npm.
To check version of npm:$ npm -v
Module is a file .js and inside this file have to define a code module.exports = [nameA]
When another .js file want to use that file have to define a code nameA = require('that file')
.
To using any module built in NodeJS:
var fsy = require('fs')
with: fsy
: in your option, fs
: this is a NodeJS's module.
You can read others module at: here.
To install:
- Installing nmp (done when you installed nodejs)
- Initialize npm for your project:
$: npm init
- By tap enter for all default.
- After input info your project, in your project will be add a package.json file.
- Installing which module third party you want with:
$ npm install [name modele] --save
, (--save means that module will be stored your project)
-
Converting Object to String:
JSON.stringify(nameObject)
-
Converting String to Object:
JSON.parse(nameString)
- Synchronous: Assume that, you have 2 tasks A and B. If you use Sync, you will only done task A and then you make task B.
- Asynchronous: Similar you also have 2 above task. But during task A going on, you can make task B without wait task A done.
- This is concept that show a hard code, more loop, terrible reading....
- If inside a function use multip promise function, I have to put
async
in front of that function.