How to Search for Specific Text in Node Modules on Windows

Learn how to search for specific text (like permissions or keywords) in the node_modules directory on Windows using PowerShell, Command Prompt, and Git Bash. This guide covers alternatives to grep, making debugging easier for developers working with React Native and other JavaScript frameworks.

How to Search for Specific Text in Node Modules on Windows

When working with React Native or Node.js projects, sometimes you need to check if a certain permission or keyword is present inside the node_modules directory. On Linux/macOS, you can use the grep command to search recursively. However, Windows does not support grep by default.

This guide will show you how to achieve the same functionality using PowerShell, Command Prompt (CMD), and Git Bash.


1. Using PowerShell (Recommended)

PowerShell provides a built-in way to search for text recursively across files. To check if a specific permission (e.g., RECEIVE_SMS) is present inside node_modules, use the following command:

Get-ChildItem -Path .\node_modules\ -Recurse -File | Select-String -Pattern "RECEIVE_SMS"

Explanation:

  • Get-ChildItem -Path .\node_modules\ -Recurse -File → Recursively fetches all files inside node_modules.

  • Select-String -Pattern "RECEIVE_SMS" → Searches for the specified text inside those files.

Example Output:

node_modules\react-native-otp-verify\android\src\main\AndroidManifest.xml:5: <uses-permission android:name="android.permission.RECEIVE_SMS" />

This confirms that the permission exists in a particular file.


2. Using Git Bash (If Installed)

If you have Git for Windows, you can use grep inside Git Bash:

grep -r "RECEIVE_SMS" node_modules/

This works similarly to Linux/macOS systems.


3. Using Windows Command Prompt (CMD)

For those who prefer CMD, the built-in findstr command can be used:

findstr /S /I "RECEIVE_SMS" node_modules\*.*

Explanation:

  • /S → Searches in all subdirectories.

  • /I → Makes the search case-insensitive.

  • node_modules\*.* → Searches inside all files in node_modules.

Example Output:

node_modules\some-package\config.xml: <uses-permission android:name="android.permission.RECEIVE_SMS" />

Conclusion

If you're working on React Native, Node.js, or any JavaScript project, searching through node_modules is sometimes necessary for debugging.

  • PowerShell is the best choice as it's built into Windows.

  • Git Bash allows you to use grep if you have Git installed.

  • CMD's findstr is another quick alternative if PowerShell is not available.

By using these methods, you can quickly find permissions, keywords, or configuration details in your project dependencies.


💡 Tip: If you frequently need to search inside node_modules, consider using an advanced code editor like VS Code with built-in search functionality (Ctrl + Shift + F).