0% found this document useful (0 votes)
6 views4 pages

NPM Tutorial

The document is a tutorial on NPM (Node Package Manager), detailing its installation, project creation, and basic commands for managing JavaScript packages. It covers steps for creating a project, setting up a .gitignore file, pushing to a git repository, and publishing packages to the NPM registry. Additionally, it explains the structure of package.json and how to install and start projects using NPM commands.

Uploaded by

lihomahowareyou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

NPM Tutorial

The document is a tutorial on NPM (Node Package Manager), detailing its installation, project creation, and basic commands for managing JavaScript packages. It covers steps for creating a project, setting up a .gitignore file, pushing to a git repository, and publishing packages to the NPM registry. Additionally, it explains the structure of package.json and how to install and start projects using NPM commands.

Uploaded by

lihomahowareyou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NPM Tutorial

Table of Contents
NPM Tutorial.....................................................................................................................1
What is NPM?............................................................................................................................2
How to install NPM....................................................................................................................2
Create a project..........................................................................................................................2
Create .gitignore file to prevent upload unused file to repository...............................................2
Push file to git repository...........................................................................................................3
Clone the repository and install..................................................................................................3
NPM Install................................................................................................................................3
NPM Start..................................................................................................................................3
Ref:............................................................................................................................................3
What is NPM?
 NPM is Node Package Manager which is an online repository allow user to
download Javascript package.

How to install NPM


 Using NVM (Node Version Manager) to install Node and NPM
 curl -o- [Link] |
bash

Create a project
1. Mkdir my-project
2. Cd my-project
3. Create a [Link]
a. Npm init
4. Install a dependency to project
a. Npm install jquery –save
b. Package was installed to node_modules folder
c. –save is also update the [Link]
1. cat [Link]
2. {
3. "name": "myproject",
4. "version": "1.0.0",
5. "description": "This is my project",
6. "main": "[Link]",
7. “repository”: {
8. “type”: “git”,
9. “url”: “[Link]
10. },
11. "scripts": {
12. "test": "no test command now"
13. },
14. "keywords": [
15. "myproject"
16. ],
17. "author": "tester",
18. "license": "ISC",
19. "dependencies": {
20. "jquery": "^3.4.1"
21. }
22. }

Create .gitignore file to prevent upload unused file to repository


.gitignore Node_modules
Push file to git repository

Commands
1. Create an empty repository in git (e.g. myproject)
2. Git clone [Link]
3. Add file from local to repository
a. Git add [Link]
b. Git commit -m “myproject”
c. Git push origin master

Clone the repository and install

Commands
1. Git clone [Link]
2. Npm install

Go to the git project folder


 cd myproject

Set the public registry


 Npm config set registry [Link]

Login to registry
 Npm login
o UserID: Lihomahowareyou
o Password:
o Email: lihomahowareyou@[Link]

Publish to registry
 Npm publish –access=public

Install npm package


 Npm install myproject

NPM Install
 Install the dependencies defined in [Link] by default
 Install the [Link] precedence if both exists.
NPM Start
 Run the start property in script object of [Link]
 If no start property, it run “npm [Link]”

[Link]
1. Name
o If plan to publish the package, name and version are required and must
unique
o Name + version (unique identify package)
 Main
o Is a module ID
o Entry point of program
o If package is named “foo”, require(“foo”) then module’s exports object will
be returned.

Ref:
NPM CLI doc [Link]
NPM tutorial [Link]
%B6%E9%96%8B%E5%A7%8B-%E4%BD%BF
%E7%94%A8npm%E5%A5%97%E4%BB%B6-317beefdf182

You might also like