0

hey guys so I'm having problems with trying to get my readme file to generate. Every time I put node index.js in to the terminal it says the fs.writetofile is not a function. but it still lets me put in the information of the readme.

this is the index.js file

const inquirer = require('inquirer');
const fs = require('fs');
const generateMarkdown = require('./utils/generateMarkdown');
const path = require('path');

// TODO: Create an array of questions for user input
//this is the array of questions to put in the readme

function init(){

    inquirer.prompt([

        { 
          type: "input",
          message: "What is the title",
          name: "title",  
             },

        { 
          type: "input",
          message: "give a description",
          name: "description",  
             },

        {
           type: "input",
           message: "how do you install it",
           name: "installation",
        },
        
        {
            type: "input",
            message: "How do use it",
            name: "usage",
        },
          
        {
            type: "input",
            message: "github username",
            name: "name"
        },
        
      ]).then((data) => {
        const filename = `${data.title}.md`;

        fs.writeToFile(filename, generateMarkdown(data)), (err) =>{
          if (err){ 
              return console.log(err);
          }
          console.log('you have created a readme file.')
        }

      }
      );
    };

    
      
    //initialize app

    init();

//this is the generatmarkdownfile
    const InputPrompt = require("inquirer/lib/prompts/input");

//function for readme 
function generateMarkdown(data) {
  return `
  # ${InputPrompt.title}
    
  ## Description
      
  ${InputPrompt.description}
    
    
  ## Installation
    
  ${InputPrompt.installation}
    
  ## Usage
    
  ${InputPrompt.usage}
    
  ## Name
     
  ${InputPrompt.name}
  `;
  }
   

module.exports = generateMarkdown;

0

1 Answer 1

1

Method name to write to file is not called writeToFile but it's called writeFile actually.

So replace fs.writeToFile with fs.writeFile.

Edit: The code below fixes the syntax issue you have with that extra parenthesis. Check what I have written in the comments.

fs.writeFile(filename, generateMarkdown(data), (err) => {
    if (err) {
        return console.log(err);
    }
    console.log('you have created a readme file.')
});
Sign up to request clarification or add additional context in comments.

4 Comments

thank you! now it's giving me a invalid callback on line 46, I've tried moving it out of the .then function but it made it stopped the questions from prompting, do i have to call it when i am calling init(); ? thanks for the help
or do i have to declare a path?
The callback is not being passed inside the writeFile function because of an extra parenthesis you have in your code right after generateMarkdown(data).
i never would have saw that thank you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.