I am looking for a nodejs script that will replace the IN
with the OUT
below.
IN
/* api_start ====
app.use('/api',require('./api/api'));
app.use('/sms',require('./api/sms'));
==== api_end */
or
// app.use('/api',require('./api/api'));
// app.use('/sms',require('./api/sms'));
OUT
app.use('/api',require('./api/api'));
app.use('/sms',require('./api/sms'));
Basically just uncommenting those lines of code.
or
just replace a comment like, /* api_here */
with contents from a file which would contain the middle where from the OUT
above (api.js
).
UPDATE
from: https://stackoverflow.com/a/25072070/3066142
The following will work if i could just write the regex to recognize that line. Below is my attempt
// require:
var replace = require("replace");
// use:
replace({
regex: "//\s+app\.use\('/api',require\('\./api/api'\)\);", // string to be replaced
replacement: "test worked!!", // replacement string
paths: ['dist/server.js'], // path/to/your/file'
recursive: true,
silent: true,
});