git init
git remote add origin githubrepositoryURL
This make the git to catch the project we are working on
npm init
package.json is a NodeJS file and the file contains information about the developers, the project, and also the packages used.
There are three important objects in package.json:
1. "main"
2. "scripts" : Something (js files) that I want to run
3. "dependencies"
When a package.json is created, there's gonna be an object says "main":"index.js".(Of course it is when you create a file called index.js)
execute js file with node:
node index.js
But we are not going to use this term a lot because "main" is primary entry point. and this is used when we publish the package and someone wants to install the program.
So in this case we need to create "scripts".
"scripts" is something we want to run for ourselves.
"scripts":{
"nameToCall":"node fileName.js"
},
Difference between the "scripts" and "main" is that it has node in front of the filename. (So fileName.js is watched by NodeJS already?🤔)
and this is how to run on the terminal with npm.
(make sure you call it inside of the folder)
npm run nameToCall
A package to build server.
npm i express
or
npm install express
When you install express on the project, you will see
dependencies indicates the packages which required to run the project
So, when you install the express, there's gonna be an object:
"dependencies":"express": "^4.18.1"
Which tells you the package and the version of the package.
This dependencies information not only tells you what kind of packages are there, but also let you install all the packages when you simply
npm i
or
npm install
npm reads the package.json and reads the dependencies and downloads the exact same version of the packages for you!
The advantage of dependencies is that the project becomes very light (using .gitignore).
You don't have to upload or download the heavy project contains all the packages. (Great benefit when you work in a team or in different computer)
Babel is a package which translates JavaScript syntax which NodeJS can't understand (new version of syntax) to an old version syntax which NodeJS can understand and process. Link to Babel
npm install --save-dev @babel/core
When you install babel packages on in the project, you will see new type of dependencies object in your package.json file.
"devDependencies": {
"@babel/core": "^7.18.6",
}
Just like dependencies, it is something is needed. If the dependencies are the packages required to run program, "devDependencies" are the packages which programmers, or the developers needs.
A package will watch javaScript files and if Nodemon finds the edit from the file, it will automatically restart. (Never let my console die.)
"scripts":{
"node index.js"
}
Runs index.js with NodeJS.
"scripts":{
"babel-node index.js"
}
This makes the babel to run the NodeJS.
"scripts":{
"nodemon --exec babel-node index.js"
}
nodemon executes "babel-node index.js"