- It is Javascript runtime Environment
- It allows you to run JavaScript on the server-side (outside the
browser).
- One of its use is server side programming ,and that’s why we will
use it.
# Install Node.js
- Open bash [type -> node , to check]
Read Evaluate Print Loop
- Type => node [u enter node worls so command like ls will not
work]
# How to run files using node ?
- Touch script.js
- node script.js [this will run node.js]
# Process in Node
Ex -> npm install figlet
Then u will see files like node_modules , package-lock.json ,
package.json
a. mkdir figlet
b. cd figlet
c. npm install figlet
d. create new file index.js inside figlet folder to use figlet
e.
f. Paste from npm website ,,,, as we r requiring package so no
need to use ./ just name of package is enough.
- For example if u want to send ur project to someone so no
need to send whole node_modules just package.json
enough.
- Also ixf node modules got deleted and we only have
package.json then we can easily install node_modules
[package.json already knew what dependencies need to be
installed]
- When we upload project on git no need to upload
node_modules just package.json enough.
- npm install [to get back node modules]
# Creating ur own project
a. mkdir MyProject
b. now create ur own package.json file, for that
c. npm init [give respective detail]
d. package.json created
e. now suppose npm install figlet [node modules came as
fliget came]
if we clone someone project and node modules not their don’t
worry , u can install from package.json .
- till now we were installing locally
- if we install locally then we can’t use that package outside
that folder
- but installing globally is best.
- But just to teach u we can install globally also
- Just add -g
- Npm install -g <package name> [but get administrator
acess]
- Either do require in whole project or do import in whole
project
- In require whole thing come but in import we choose.so we
can save memory if we use import