Test local node package

Source: Internet
Author: User
@ Subject: test the local node package
@ Author: leinov
@ Date: 2018-10-25

When writing a node package, we need to test the package locally before releasing it to NPM. Suppose we have a locally written node package.xcxutilPackage and a project to test the packagemyappIn the same folderprojectThe following two methods are available:myappTest localxcxutilPackage

|-- project    |-- myapp    |-- xcxutil
Install xcxutil in the relative path

Go to the project directory, find the xcxutil package in the corresponding path, and install it directly.

cd myappnpm install ../xcxutil

Then entermyappInnode_modulesCheck whether the folder is successfully installed. Generally, if the path is correct and the node package is correctly written, the installation is successful, so that you can usexcxutil.

const xcxutil = require('xcxutil');

Note,myappThe directory must havepackage.jsonFile. Otherwise, no node package can be installed.

Connect to global test with NPM Link

The above situation is that the node package and test project are in the same folder, so it is very convenient to find the path, but in many cases our local projects are distributed in different folders, so it is very troublesome to find the path, so we recommend that you usenpm linkThis method connects the node package to the global environment.

cd xcxutilnpm link

Run the preceding command to obtain the following output:

/Users/leinov/.nvm/versions/node/v8.11.3/lib/node_modules/xcxutil -> /Users/leinov/project/xcxutil

It meansprojectUnderxcxutilConnect to the globalnode_modulesNext, we enter the globalnode_modulesYou can also view the packagexcxutilPackage

Then link the package in MyApp to test the usage.

cd myappnpm link xcxutil

In this way, xcxutil will be installed under MyApp, and modifications made under xcxutil will also be synchronized to MyApp to implement local testing,

Cancel global connection

cd xcxutilnpm unlink

Xcxutil has been released. Welcome to GitHub.

Original article address: 1190000016799775

Test local node package

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.