Skip to content

Y #123

Description

@Juan1233457

Trying to work with node/javascript/nfts, I am a noob and followed along a tutorial, but I get this error:

error [ERR_REQUIRE_ESM]: require() of ES Module [...] is not supported. Instead change the require of index.js [ in my file...] to a dynamic import() which is available in all CommonJS modules
My understanding is that they've updated the node file, so i need a different code than that in the tutorial, but i don't know which one I'm supposed to change, where and to what. Please be as specific as you can

const FormData = require('form-data');
const fetch = require('node-fetch');
const path = require("path")
const basePath = process.cwd();
const fs = require("fs");

fs.readdirSync(${basePath}/build/images).foreach(file).forEach(file => {
const formData = new FormData();
const fileStream = fs.createReadStream(${basePath}/build/images/${file});
formData.append('file',fileStream);

let url = 'https://api.nftport.xyz/v0/files';

let options = {
  method: 'POST',
  headers: {
    Authorization: '[...]',
  },
  body: formData
};

fetch(url, options)
  .then(res => res.json())
  .then(json => {
   const fileName = path.parse(json.file_name).name;
   let rawdata = fs.readFileSync(`${basePath}/build/json/${fileName}.json`);
   let metaData = JSON.parse(rawdata);

   metaData.file_url = json.ipfs_url;

   fs.writeFileSync(`${basePath}/build/json${fileName}.json`, JSON.stringify(metaData, null, 2));

   console.log(`${json.file_name} uploaded & ${fileName}.json updated!`);
  })
  .catch(err => console.error('error:' + err));

})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions