Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
nodejs: imported function not returning value

I have a function checkIsDir and I have imported it to the main file cli.js but I am unable to access the value which is been returned, in this case, it is true.

checkIsDir.js

const fs = require('fs')
const listr = require('listr')

function checkIsDir(path) {
  const tasks = new listr([
    {
      title: 'Checking if path is a directory',
      task: () => {
        try {
          fs.lstatSync(path).isDirectory()
          // return true if the path is a directory
          return true
        }
        catch (err) {
          throw new Error(`Path ${path} is not a directory`)
        }
      }
    }
  ])
  tasks.run().catch(err => {
    throw new Error(err)
  })
}

module.exports = checkIsDir

cli.js

#! /usr/bin/env node

const inquirer = require('inquirer');
const fs = require('fs')

const questions = require('./data/questions');
const checkIsDir = require('./lib/checkIsDir');
const spiltPath = require('./lib/splitPath');

const path = process.cwd();

inquirer.prompt(questions).then(async (answers) => {
  console.log(checkIsDir(answers.path))
  if (checkIsDir(answers.path) === true) {
    spiltPath(answers.path);
  }
  else {
    console.log('Oh no')
  }
});

terminal output

splitPath.js

function spiltPath(path) {
  var spiltArray = path.split('/');
  var folderName = spiltArray[spiltArray.length - 1];
  console.log(folderName);
}

module.exports = spiltPath
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda