How to fix error- nodemon.ps1 cannot be loaded because running scripts is disabled on this system, (without security risk)?
I'd recommend using RemoteSigned
as opposed to Unrestricted
, and limiting the policy to the current user if possible.
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
RemoteSigned: "The default execution policy for Windows server computers."
Other than that, I wouldn't worry about it too much, as it's not intended to be a security mechanism. See this quote from the docs:
"The execution policy isn't a security system that restricts user actions. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally."
There is no security risk whatsoever associated with allowing remoted signed scripts to run on your local machine. It basically means you can execute local unsigned scripts i.e scripts written by you while scripts from a remote source (nodemon in this case) must be signed by a trusted authority.
P.S: If you're on windows, you can just go to settings >> update and security >> for developers >> check the box beside change execution policy to allow local powershell scripts to run without signing
For those who are not aware of how to solve this error using Windows PowerShell
- Open PowerShell (Run As Administrator)
- Check the current execution policy using this command
Get-ExecutionPolicy
# You should get 'Restricted'
- Run this command to make it 'Unrestricted'
Set-ExecutionPolicy Unrestricted
- Check again whether execution policy changed by running this command
Get-ExecutionPolicy
# You should get 'Unrestricted'
- Now try to run nodemon on your project
nodemon 'filename.js'
Hope this would be helpful