Project Initialization
Start by creating a new project directory.
$ mkdir myapp
$ cd myapp
Run the command below to create the main configuration file called ./package.json
.
$ npm init --yes
Install the nodemon
package globally which we will use in development for auto-reloading our code when the code changes.
$ npm install -g nodemon
Create also its configuration file ./nodemon.json
.
{
"verbose": true
}
Create a simple application within the ./src
directory.
$ mkdir src
$ echo 'console.log(`Hello World!`);' >> ./src/index.js
Open the ./package.json
file and set the variables as shown below.
{
"main": "./src/index.js",
"scripts": {
"start": "node ./src/index.js"
}
}
A common convention is also to create a ./README.md
file with the description of your application.
$ touch README.md
Every project should use some kind of code revision control. Git is the most popular, free and open source distributed version control system. Let's initialize the repository.
$ git init .
Create a new file called ./.gitignore
with a list of files and folders which should not be committed into Git repository.
$ (echo .DS_Store; echo .vscode; echo node_modules) >> .gitignore
We can now do the initial commit.
$ git add .
$ git commit -m 'project initialized'
Run npm start
to run the application. Run nodemon --exec npm start
to start the application in development.