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