Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@retro_ig/file-execute

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@retro_ig/file-execute

A module to easily get and execute files in a folder

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

file-execute

Tired of using require? I got you! Use this package to easily read files and transfer data between them

Installation

npm i @retro_ig/file-execute

Examples

const { FileExecute } = require('@retro_ig/file-execute')
const fileExecute = new FileExecute('path/to/your/folder') //path to your folder with all your js files
async function exampleFunction() {
    await fileExecute.execute('testFile')
}
exampleFunction()

In testFile.js

module.exports = {
    name: 'testFile', //we will use the name to call the execute function in the main file
    async execute() {
        try {
            console.log('Hello World!')
        } catch (error) {
            console.log(error)
        }
    }
}

Data Transfer Module

Now file Execute package doesn't just run files. That's too borning. It has its own module for global data. We will go back to the first Example and add the module there!

const { FileExecute, dataTransferer } = require('@retro_ig/file-execute')
const fileExecute = new FileExecute('path/to/your/folder') //path to your folder with all your js files
async function exampleFunction() {
    await dataTransferer.setData({
        foo: 'bar' // The data must be an object!
    })
    await fileExecute.execute('testFile')
}
exampleFunction()

In testFile.js

const { dataTransferer } = require('@retro_ig/file-execute')
module.exports = {
    name: 'testFile', //we will use the name to call the execute function in the main file
    async execute() {
        try {
            const transferedData = await dataTransferer.getData()
            console.log(transferedData.foo) //expected output: "bar"
        } catch (error) {
            console.log(error)
        }
    }
}

Passing Custom Data

On version 0.1.3 or higher, you can pass your own custom data with the execute() function
We will go back to our example again to learn how to pass custom data!

const { FileExecute } = require('@retro_ig/file-execute')
const fileExecute = new FileExecute('path/to/your/folder') //path to your folder with all your js files
async function exampleFunction() {
    await fileExecute.execute('testFile', {
        foo: "bar"
    })
}
exampleFunction()

In testFile.js

module.exports = {
    name: 'testFile', //we will use the name to call the execute function in the main file
    async execute(customData/** We can pass in custom data value here to read all the values **/) {
        try {
            const data = customData.foo
            console.log(data) //expected output: Bar
        } catch (error) {
            console.log(error)
        }
    }
}

Found an issue?

Open an issue at our github page!

FAQs

Package last updated on 22 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc