title: Hyperledger Fabric get User Private Key from Node.js SDK 2.2 version
body: <p>I am building a Node.js application that uses the Hyperledger Fabric SDK 2.2 version that interacts with the blockchain network.</p>
  <p>What I want to achieve, is to retrieve the Private Key of the user making the request from the Node.js application after retrieved the identity of the wallet.</p>
  <pre><code>// Create a new file system based wallet for managing identities.
        const walletPath = path.join(process.cwd(), 'wallet');
        const wallet =  await Wallets.newFileSystemWallet(walletPath);
        logger.info(`API/` + requestType + `: Wallet path: ${walletPath}`);
  
        // Check to see if we've already enrolled the user.
        const userExists = await wallet.get(in_username);
        if (!userExists) {
            logger.info('API/` + requestType + `: An identity for the user: '+in_username+' does not exist in the wallet');
            //return 'An identity for the user: &quot;'+in_username+'&quot; does not exist in the wallet';
            throw new Error('An identity for the user: &quot;'+in_username+'&quot; does not exist in the wallet');
        }
  
        if (userExists &amp;&amp; userExists.type === 'X.509') {
          console.log(&quot;userPrivateKey 1 : &quot; + userExists.type);
          
          const privateKey = (userExists as X509Identity).credentials.privateKey;
  
          console.log(&quot;userPrivateKey 1 : &quot; + privateKey);
  
        }
  </code></pre>
  <p>So, I have seen from the documentation the above example of retrieving the private key. I retrieve successfully the identity and get the type of the certificate which is truly X509.</p>
  <p>But after that, I am unable to cast or convert the identity to X509 Identity in order to retrieve the private key.</p>
  <p>At first I am not able to proceed as this error comes up in the row:</p>
  <pre><code> const privateKey = (userExists as X509Identity).credentials.privateKey;
  </code></pre>
  <p>Error:</p>
  <pre><code>Type assertion expressions can only be used in TypeScript files.
  </code></pre>
  <p>I am not expert in Node.js and I have been informed that this might not be possible to &quot;cast&quot;. But I am confused since I have seen that in the documentation of the Hyperledger Fabric Node SDK.</p>
  <p>Anyone knows any solution on that, or even a hint on how to continue?</p>
  <p>Thank you</p>