The npm package for ssh-keygen is causing an issue where it returns undefined values for both

The output of the generated keys is not defined for both the private and public keys. Refer to [ssh-keygen][1]

Keys successfully created!

Private key: undefined
Public key: undefined

async generateAndWriteSSHKeyv2() {
return new Promise((resolve, reject) => {

    let currentTime = new Date().getTime();
    var location = path.join(process.cwd(), `contents/apps/SSHkeys/key_${currentTime}`);
    var comment = 'example';
    var password = 'example';
    var format = 'PEM';
    keygen({
        location: location,
        comment: comment,
        password: password,
        read: true,
        destroy: false,
        format: format,
        size: 4096,
    }, (err, output) => {
        if (err) resolve(console.log('An error occurred: ' + err));
        console.log('Keys successfully created!');
        console.log('Private key: ' + output.key);
        console.log('Public key: ' + output.pubKey);
        resolve({
            location,
            comment,
            password,
            read: true,
            format,
            size: 4096,
            output
        })
    });
})
};

Answer №1

I stumbled upon this code snippet that may be useful for your reference

  generateSshKeyFiles(name, next) {
    keygen({
      location: name,
      read: true,
      destroy: true,
    }, function(err, out) {
      if (err) {
        next(err);
      } else {
        let sshKeyFiles = [{'content': out.pubKey, 'fileName': name+'.pub'}, {'content': out.key, 'fileName': name}];
        next(null, sshKeyFiles);
      }
    });
  }

Try incorporating a similar function and see if you encounter the same error message.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating coordinates on Google Maps using setTimeOut with jQuery and JavaScript

I am currently working on updating the markers and users' positions every five seconds so that the users can see their live position updates. I have managed to retrieve the current coordinates and update them at the correct interval, but I am struggli ...

Divs that can be sorted are being shifted downwards within the swim lanes

JavaScript code snippet here... CSS code snippet here... HTML code snippet here... ...

Explore the Star Wars API using interactive buttons to navigate between different planetary pages

I've been working with the incredibly popular StarWars API and have successfully extracted data from the initial page of planets after some research. However, a new challenge has arisen. My task now is to implement buttons that allow users to navigat ...

Selenium's click() method in Python seems to experience issues when used within a script, but functions properly when used through

While working with python 3 selenium, I encountered an issue when trying to login to the Zomato website. When running a script, the login button was clicked but the dialog box did not open. However, when executing the same statements in the command line or ...

"Step-by-step Guide to Implementing Auto-Incrementing Image Slider in

I am currently working on auto-changing images in my application that are sourced from an array called imgslider[]. Below is the component file for MY: import { Component, OnInit, Input } from '@angular/core'; import {HeadService} from '.. ...

What is the best way to manage a string containing quotes?

Currently, I have a JavaScript function that is being called using the following code: <a href='javascript:void(0)' onclick='javascript:onEditRevPrepare(" <%#Convert.ToString(Eval("ReviewTitle"))%>"> The issue arises when th ...

What is the best approach to displaying child nodes in JsTree when they are only generated after the parent node is expanded?

Dealing with multiple children nodes under a parent can be tricky. For instance, when trying to open a specific node using $("#jstree").jstree("open_node", $('#node_27'));, you may encounter an issue where the parent node is not initially open, c ...

What are the steps to installing the most recent LTS version of Node on Ubuntu 16.04?

I recently obtained the source code (.tar file) from this website Can someone guide me on how to install Node using the tar file on my system? ...

navigating to the start of a hyperlink

I'm having issues with scrolling to anchors and encountering 3 specific problems: If I hover over two panels and click a link to one of them, nothing happens. When I'm on section D and click on section C, it scrolls to the end of section C. ...

I need help figuring out how to mention an id using a concatenated variable in the jquery appendTo() method

Using jQuery, I am adding HTML code to a div. One part of this code involves referencing a div's ID by concatenating a variable from a loop. $(... + '<div class="recommendations filter" id="recCards-'+ i +'">' + &apo ...

Understanding the flattening process of arrays using JavaScript - Detailed explanation required

Currently, I am immersed in the captivating world of Eloquent JavaScript. However, I have hit a roadblock with one of the exercises that involves flattening a multi-dimensional array. Despite my best efforts, I have been unable to crack the code. After f ...

Transmit the array to the controller

Is there a way to pass an array to the controller? I attempted the following: window.location.href = "/SomeController/SomeMethod?fields=" + SomeArray; and also tried this: window.location.href = "/SomeController/SomeMethod?fields[][]=" + SomeArray; Whe ...

Synchronization Issue between Ionic Popover templateURL and Angular ng-model

In my project utilizing the Ionic framework, I encountered an issue with the code snippet below: $scope.loginCountryCode; $scope.loginPhone; // Code continues... <div class="container"> <label class="item item-input&quo ...

Using an API to fetch a nested array for displaying data in an HTML table

I'm currently developing a program to retrieve and display data from the OpenSky-network API. The API returns an array of airplane information arrays, and I am looking for a way to present this information in an HTML table. Specifically, I want to ext ...

Update the content within a document and implement jQuery to make it clickable

Within my webpage, there is a random occurrence of the word -FORM-. I am looking to replace this word with another text that includes dashes for creating a clickable div. Despite having some code that successfully replaces the text, it lacks the function ...

The attempt to run 'setProperty' on 'CSSStyleDeclaration' was unsuccessful as these styles are precalculated, rendering the 'opacity' property unchangeable

I am attempting to change the value of a property in my pseudo element CSS class using a JavaScript file. Unfortunately, I keep encountering the error mentioned in the title. Is there any other method that can be used to achieve this? CSS Code: .list { ...

Guide: Initiating an action in NuxtJs

I am attempting to trigger an action in my Vue component from my Vuex store. Below is the content of my aliments.js file in the store: import Vue from 'vue'; import Vuex from 'vuex'; import axios from 'axios'; Vue.use(Vuex, ...

The browser is unable to load the local JSON file due to an XMLHttpRequest error

I have been attempting to import a json file into a table, after conducting thorough research I finally discovered some solutions on how to achieve this. However, when trying to implement it in Chrome, I encountered the following error: XMLHttpRequest ...

How to efficiently pass props between components in NextJs

This is the project's file structure: components ├─homepage │ ├─index.jsx ├─location │ ├─index.jsx pages │ ├─location │ │ ├─[id].jsx │ ├─presentation │ │ ├─[id].jsx │ ├─_app.jsx │ ├─index.jsx ...

Improving efficiency in protractor click tests by implementing For-Loops

Query: How can I successfully click on each link within a ul > li a in one single test? Issue: Although the test is currently passing, it is not effectively clicking on the links. This can be verified by the absence of redirection or the expected 2000m ...