
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
node-replace
Advanced tools
Maintaned Fork from harthur/replace
replace
is a command line utility for performing search-and-replace on files. It's similar to sed but there are a few differences:
npm install node-replace -g
You can now use replace
and search
from the command line.
Replace all occurrences of "foo" with "bar" in files in the current directory:
replace 'foo' 'bar' *
Replace in all files in a recursive search of the current directory:
replace 'foo' 'bar' . -r
Replace only in test/file1.js and test/file2.js:
replace 'foo' 'bar' test/file1.js test/file2.js
Replace all word pairs with "_" in middle with a "-":
replace '(\w+)_(\w+)' '$1-$2' *
Replace only in files with names matching *.js:
replace 'foo' 'bar' . -r --include="*.js"
Don't replace in files with names matching *.min.js and *.py:
replace 'foo' 'bar' . -r --exclude="*.min.js,*.py"
Preview the replacements without modifying any files:
replace 'foo' 'bar' . -r --preview
See all the options:
replace -h
There's also a search
command. It's like grep
, but with replace
's syntax.
search "setTimeout" . -r
You can use replace from your JS program:
var replace = require("node-replace");
replace({
regex: "foo",
replacement: "bar",
paths: ['.'],
recursive: true,
silent: true,
});
By default, replace
and search
will exclude files (binaries, images, etc) that match patterns in the "defaultignore"
located in this directory.
If replace
is taking too long on a large directory, try turning on the quiet flag with -q
, only including the necessary file types with --include
or limiting the lines shown in a preview with -n
.
FAQs
Command line search and replace utility
The npm package node-replace receives a total of 2,078 weekly downloads. As such, node-replace popularity was classified as popular.
We found that node-replace demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.