Node js
Global varibels
- __filename -> full fill path
- __dirname -> parent folder full path
- require -> global function used to import modules
- module -> info about current module
- process -> info about current the host device
Modules
1. make your modual
every file is a modual
- export somthing from file
- import somthing from another file
Full Example
NOTE: when you require a file all code in file will run
EXAMPLE
Terminal
2. built in moduals
- OS MODUAL
- PATH MODUAL
- FS MODUAL
- sync functions : stop all tasks until finish this task
Example
- async functions : do another task will this task are done then when this task
Full Example
- http
createServer: this method return a server object
FULL EXAMPLE
Create package.json file
Dependencies
is a packages that built by another programers and they are published it in npm store and you can use it in your project
How to install dependencies package ?
Devdependencies
is a dependencies that you just need it in development step (you don't need it in production) like nodemon package.
How to install devdependencies package ?
Example
Note : nodemon is a tool that helps develop Node.js based applications by automatically restarting the node application.
Scripts
This will run 'nodemon index.js'
uninstall package
convert any async function into Promise
OR YOU CAN GET READ AND WRITE AS PROMISES
EVENTS
Send data with the event
Server use Event