
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
replace-js-file
Advanced tools
A simple utility to quickly replace the contents of text blocks in Json format within JavaScript files.
A simple utility to quickly replace the contents of text blocks in Json format within JavaScript files.
# Using npm, installing to local project
npm i --save replace-js-file
# Using npm, installing globally for global cli usage
npm i -g replace-js-file
# Using yarn
yarn add replace-js-file
//Load the library
const replace = require('replace-js-file');
var path = require("path");
var file = path.join(__dirname,'<FILE_PATH>');
var find = {
"email": {
"type": "String",
"unique": true,
"required": true
},
"password": "String"
};
var input = {
"email": {"type":"String","unique":true,"required": true},
"password": "String",
"usergroup": {
"type": "ObjectId",
"ref": "group",
"required": true
}
};
replace(file,find,input,function(err,file_path){
console.log("path: ",file_path);
});
replace(file,find,input)
.then(response => {
console.log(response.message);
}, err => {
console.log(err.message);
});
var file_output = path.join(__dirname,'<FILE_PATH>');
replace(file,find,input,file_output,function(err,file_path){
console.log("path: ",file_path);
});
var file_output = path.join(__dirname,'<FILE_PATH>');
replace(file,find,input,file_output)
.then(response => {
console.log(response.message);
}, err => {
console.log(err.message);
});
When it is a promise, it returns an object with the answer, in it there are two variables, success and message.
success Initiates that everything is successful and message details the result of the operation.
When callback is used, two parameters are returned, the first is an error and the second the path of the created or modified file.
(MIT License)
Copyright 2019, Fabian Vargas, co-founder at Donec Lab
FAQs
A simple utility to quickly replace the contents of text blocks in Json format within JavaScript files.
We found that replace-js-file 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.