After successfully installing Node.js, you can use the Node Package Manager (NPM) tool to create a new Node.js project to start working on it. How is it in details? In this tutorial, I will guide you all to do this.
First, open Terminal (macOS or Linux) or Console (Window), go to a directory where you want to create the project, then enter the following command:
1 |
npm init |
Myself as follows:
Here, to create a Node.js project, we need to fill in some information about our project. First, as you can see, is the package name information. This is the name of the project you want to create. The value “(javascript)” is the default value. You can leave it as default or fill it with your needs. Then hit Enter, myself as follows:
Next, as you can see, is the version information. I’ll leave it to default and hit Enter to continue:
Add some description of your project. You can add your own and then press Enter to continue, as follows:
The entry point is the file that contains the main script for our project. You can leave the defaults, we can edit them later, and then press Enter.
If you already know the command to run the test in Node.js then you can declare it here. I have no need so will leave this information empty then press Enter.
If you have a need to use Git to manage source code, then you can enter information about Git Repository here. I will leave this information empty, then press Enter.
keywords are some information that you can fill in so that users can search your project. I have no need, so will leave this information empty, then press Enter to continue.
Author is the author’s information. Please enter your name: D, then press continue.
License relates to the copyright of the project. You can enter the license information according to your needs or use common licenses such as BSD-3-Clause, MIT, ISC, … Here, I will default and then Enter.
This is the window to confirm the information that you just entered. If OK then press Enter to finish creating the new Node.js project using Node Package Manager.
Check the current directory, you will see a file named package.json containing the information about the Node.js project that we just entered. My result is as follows:
1 2 3 4 5 6 7 8 9 10 11 |
{ "name": "nodejs-example", "version": "1.0.0", "description": "Node.js Example", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Khanh Nguyen", "license": "ISC" } |