Preface
With the widespread application of Node.js in Web development, many people have begun to use it as the basis for their own development. However, some novices may encounter some problems when installing and using globally installed modules. This article will solve some problems where globally installed modules cannot be read when using Node.js.
Problem Description
When using Node.js, sometimes we will install some modules globally through npm, such as nodemon, express, etc. However, when opening the command line and trying to use these modules through the command line, we may encounter some problems, as shown below:
nodemon : 在此系统上禁止执行脚本。有关详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkID=135170 中的运行 Policy。 所在位置 行:1 字符: 1 + nodemon + ~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
or
'express' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
This situation means that we installed The module cannot be read from the command line, why?
Cause Analysis
This situation is usually caused by incorrect configuration of environment variables. Globally installed modules cannot be read on the command line, possibly because Node.js cannot find the relevant installation files.
When Node.js uses npm to install modules, the installed modules will be stored in the local folder by default instead of the global path. When we execute the module in the command line, Node.js will look for the path to store the module. If the path is not in the PATH environment variable of Node.js, a read failure will occur.
Solution
In order to solve this problem, we need to perform the following steps:
- Confirm the global module path of Node.js
First, we need to find out the path to the Node.js global module. This can be viewed on the command line using the following code:
npm root -g
This command will return the path to the Node.js global module, for example:
C:UsersUsernameAppDataRoaming pm ode_modules
- Add the Node.js global module path to In the environment variables
Open the control panel on your computer, find and open the "Environment Variables" option, as shown below:
In the "Environment Variables" window, find the "Path" option under "System Variables" and click the "Edit" button. In the Edit Environment Variables window, click the New button and copy-paste the Node.js global module path into the option:
C:UsersUsernameAppDataRoaming pm ode_modules
- Restart command line
After adding the environment variables, close and reopen the command line, or execute the following command in the opened command line to update the environment variables:
refreshenv
Now, we can try to install the module globally again. For example, execute the following code to start nodemon:
nodemon
Or start the express application:
express myapp
Conclusion
This article solves the problem that the global installation module cannot be read when using Node.js The problem. If you are developing with Node.js, it is recommended to follow the above steps to solve similar problems. If you have any questions or need help, please leave a message in the comment area.
The above is the detailed content of nodejs global installation module cannot be read. For more information, please follow other related articles on the PHP Chinese website!

React'slimitationsinclude:1)asteeplearningcurveduetoitsvastecosystem,2)SEOchallengeswithclient-siderendering,3)potentialperformanceissuesinlargeapplications,4)complexstatemanagementasappsgrow,and5)theneedtokeepupwithitsrapidevolution.Thesefactorsshou

Reactischallengingforbeginnersduetoitssteeplearningcurveandparadigmshifttocomponent-basedarchitecture.1)Startwithofficialdocumentationforasolidfoundation.2)UnderstandJSXandhowtoembedJavaScriptwithinit.3)Learntousefunctionalcomponentswithhooksforstate

ThecorechallengeingeneratingstableanduniquekeysfordynamiclistsinReactisensuringconsistentidentifiersacrossre-rendersforefficientDOMupdates.1)Usenaturalkeyswhenpossible,astheyarereliableifuniqueandstable.2)Generatesynthetickeysbasedonmultipleattribute

JavaScriptfatigueinReactismanageablewithstrategieslikejust-in-timelearningandcuratedinformationsources.1)Learnwhatyouneedwhenyouneedit,focusingonprojectrelevance.2)FollowkeyblogsliketheofficialReactblogandengagewithcommunitieslikeReactifluxonDiscordt

TotestReactcomponentsusingtheuseStatehook,useJestandReactTestingLibrarytosimulateinteractionsandverifystatechangesintheUI.1)Renderthecomponentandcheckinitialstate.2)Simulateuserinteractionslikeclicksorformsubmissions.3)Verifytheupdatedstatereflectsin

KeysinReactarecrucialforoptimizingperformancebyaidinginefficientlistupdates.1)Usekeystoidentifyandtracklistelements.2)Avoidusingarrayindicesaskeystopreventperformanceissues.3)Choosestableidentifierslikeitem.idtomaintaincomponentstateandimproveperform

Reactkeysareuniqueidentifiersusedwhenrenderingliststoimprovereconciliationefficiency.1)TheyhelpReacttrackchangesinlistitems,2)usingstableanduniqueidentifierslikeitemIDsisrecommended,3)avoidusingarrayindicesaskeystopreventissueswithreordering,and4)ens

UniquekeysarecrucialinReactforoptimizingrenderingandmaintainingcomponentstateintegrity.1)Useanaturaluniqueidentifierfromyourdataifavailable.2)Ifnonaturalidentifierexists,generateauniquekeyusingalibrarylikeuuid.3)Avoidusingarrayindicesaskeys,especiall


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
