๐ A step-by-step guide to creating and setting up a Node.js project.
There are two ways to start the directory:
-
Starting the repository on an online Git service (like GitHub,...):
In this way (for example, on GitHub), we will have these at once:- An initialized git repo with a name
- A
README.md
with the repo's short description - The initial commit with the above changes
- (optional) A
LICENSE
file (Note that the license file could have no file extension or one of.txt
,md
or,rst
. The.md
and the no-extension are the most common options.) (For licenses also this repo could be useful.) - A .gitignore file (On GitHub, for example, you'll get a big .gitignore file)
Note: The
.gitignore
you're given by the platform (.e.g GitHub) probably is a very big one that contains ignores for any cases. You don't need all of them. So you need to either delete anything that you don't need or create your.gitignore
file manually and fill it out through the process of building the project as you will need it. The basic.gitignore
file is like this:/node_modules/
Don't forget to commit changes.
And finally, clone the repo (if you didn't yet) and run
npm init
command, go through steps and, then commit the changes. -
Starting the directory locally:
Steps needed in this way are:-
Create the directory with a proper name
-
Run
git init
command to initialize the repo -
Commit changes as the initial commit
-
Add the
README.md
with a very short description (then commit it) -
Add the basic
.gitignore
file like below:.gitignore
/node_modules/
And commit changes.
-
Initialize npm with
npm init
command and go through steps, and then commit the changes.
Note: Here, the difference with the other way is that you need to manually add the remote repository address to thepackage.json
later. (for example, after your first push)You need to add these to your
package.json
file:"repository": { "type": "git", "url": "git+https://github.com/samirzaee/nodejs-project-setup-guide.git" }, "bugs": { "url": "https://github.com/samirzaee/nodejs-project-setup-guide/issues" }, "homepage": "https://github.com/samirzaee/nodejs-project-setup-guide#readme"
Change URLs based on your remote repo.
-
As you probably saw and did in the steps of initializing npm, you have the license field of your
package.json
filled with what you specified. But you don't have a license file in your directory. You can add it using the steps explained in for Github remote repositories. If your remote repository is not on GitHub, you can use the GitHub steps to get the license text and then copy and paste it to your manually created license file. The license file is like one of these:- LICENSE (preferred - more common)
- LICENSE.md (preferred - more common)
- LICENSE.txt
- LICENSE.rst
And must be in the root of the directory(/repository). The first two are the most commonly used options.
For licenses also, this repo could be useful.
-