search
HomeWeb Front-endFront-end Q&Anodejs global installation module cannot be read

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:

  1. 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
  1. 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:

nodejs global installation module cannot be read

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
  1. 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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are the limitations of React?What are the limitations of React?May 02, 2025 am 12:26 AM

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

React's Learning Curve: Challenges for New DevelopersReact's Learning Curve: Challenges for New DevelopersMay 02, 2025 am 12:24 AM

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

Generating Stable and Unique Keys for Dynamic Lists in ReactGenerating Stable and Unique Keys for Dynamic Lists in ReactMay 02, 2025 am 12:22 AM

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

JavaScript Fatigue: Staying Current with React and Its ToolsJavaScript Fatigue: Staying Current with React and Its ToolsMay 02, 2025 am 12:19 AM

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

Testing Components That Use the useState() HookTesting Components That Use the useState() HookMay 02, 2025 am 12:13 AM

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

Keys in React: A Deep Dive into Performance Optimization TechniquesKeys in React: A Deep Dive into Performance Optimization TechniquesMay 01, 2025 am 12:25 AM

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

What are keys in React?What are keys in React?May 01, 2025 am 12:25 AM

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

The Importance of Unique Keys in React: Avoiding Common PitfallsThe Importance of Unique Keys in React: Avoiding Common PitfallsMay 01, 2025 am 12:19 AM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

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.