错误:ENOENT:没有使用travis和fs的此类文件或目录

时间:2018-04-20 14:46:18

标签: javascript node.js travis-ci fs

我正在尝试使用travis启动npm模块。该模块只是命中api并从该API获取数据。然后,该信息将存储在名为JSON的文件夹中,并且创建的每个文件都将存储在该文件夹中。

但是在travis中,我遇到了有关此问题的错误。 (node:4070) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: ENOENT: no such file or directory, scandir ... path to file here

import fs from 'fs-extra';
import axios from 'axios';
import zipcodes from 'zipcodes';

const fetchDealers = async function() {
  // if folder does not exist create JSON folder

  if (await !fs.readdir(__dirname + '/dist/JSON')) {
    await fs.mkdir(__dirname + '/dist/JSON');
    console.log('JSON FOLDER CREATED...');
  }

  // Loop through states and pass into dealer API

  Object.keys(zipcodes.states.abbr).map(async state => {
    const result = await axios.get(api here);

    // Loop through dealers and create file name by zip with contents of dealer
    // This will override older files, so essentailly "updating" it as well

    result.data.dealers.map(async dealer => {
      if ((await fs.readdir(__dirname + '/dist/JSON')) && dealer.zip) {
        console.log('FILE CREATED WITH ZIPCODE...');
        await fs.writeFile(__dirname + `/dist/JSON/${dealer.zip}.JSON`, dealer);
      }
    });
  });
};

fetchDealers();

我不确定你是否只能在travis中使用fs或者我做错了什么。如果您需要更多信息,请告诉我。

0 个答案:

没有答案