Skip to content

Instantly share code, notes, and snippets.

@xeusteerapat
Created July 4, 2021 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeusteerapat/13bd740c7433a9563942c318d7c6b6e5 to your computer and use it in GitHub Desktop.
Save xeusteerapat/13bd740c7433a9563942c318d7c6b6e5 to your computer and use it in GitHub Desktop.
loop create file
const axios = require('axios');
const fs = require('fs/promises');
const main = async () => {
const { data } = await axios.get('API_ENDPOINT');
const tableOfContents = data.instance.details.toc.categories.map(item => {
return item.title;
});
for (let [idx, content] of tableOfContents.entries()) {
await fs.mkdir(`${process.cwd()}/0${idx + 1}-${content}`);
}
};
main().catch(err => console.log(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment