npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@retro_ig/file-execute

v0.1.4

Published

A module to easily get and execute files in a folder

Downloads

1

Readme

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!