A versatile Node.js project designed to manage and execute code snippets efficiently. Each snippet resides in its own module, promoting modularity and ease of testing.
- Modular Snippet Management: Organize code snippets into individual modules for clarity and reusability.
- Dynamic Execution: Run any snippet by specifying its name and passing the required arguments.
- Inter-Snippet Communication: Allow snippets to invoke other snippets seamlessly.
- Automated Testing: Utilize Jest for testing snippets to ensure reliability.
The project is organized as follows:
node-playground/
├── snippets/ # Individual snippet module examples
│ ├── helloWorld.js
│ ├── mathOperation.js
│ ├── greetUser.js
│ └── nestedSnippet.js
├── src/
│ ├── loadSnippets.js # Dynamically loads all snippets
│ ├── runSnippet.js # Executes specified snippets
├── tests/
│ └── snippet.test.js # Jest test cases for snippets
├── package.json
└── README.md
-
Clone the Repository:
git clone https://github.com/athahersirnaik/node-playground.git cd node-playground
-
Install Dependencies:
npm install
You can run a snippet using the following commands:
-
Run in development mode (with auto-restart on file changes):
npm run dev
-
Run tests:
npm test
To execute a specific snippet, update src/runSnippet.js
with the desired function call and run the script:
runSnippet("greetUser", { name: "Athaher", age: 33 });
-
Create the Snippet File:
In the
snippets
directory, create a new file namedyourSnippetName.js
. -
Define the Snippet Function:
Implement your function, ensuring it accepts the
snippets
object and any necessary arguments:module.exports = (snippets, args) => { // Your code here };
-
Execute the Snippet:
Follow the Running a Snippet steps to test your new snippet.
The project uses Jest for testing.
-
Run Tests:
npm test
-
Example Test Output:
PASS tests/snippet.test.js ✓ Should execute a snippet that calls another snippet (5 ms) ✓ Should execute a nested snippet (3 ms)
Contributions are welcome! To contribute:
-
Fork the Repository:
Click the "Fork" button at the top right of this page.
-
Create a New Branch:
git checkout -b feature/YourFeatureName
-
Commit Your Changes:
git commit -m 'Add some feature'
-
Push to the Branch:
git push origin feature/YourFeatureName
-
Open a Pull Request:
Navigate to the original repository and click "New Pull Request".
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by modular coding practices and efficient snippet management.
- Utilizes Jest for testing.