Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created May 2, 2017 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/4b17772a2ea46b1b07e4402b741023c2 to your computer and use it in GitHub Desktop.
Save miguelmota/4b17772a2ea46b1b07e4402b741023c2 to your computer and use it in GitHub Desktop.
Node.js get certificate contents only using regular expression
fs.readFile('./certs/client.crt', 'utf8', (error, data) => {
const re = /[\s\S]*-----BEGIN CERTIFICATE-----\n([\s\S]*)\n-----END CERTIFICATE-----[\s\S]*/gi;
const cert = data.replace(re, '$1');
console.log(cert);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment