➰ It's never been easier to try nodejs modules!

Overview

trymodule Circle CI

A simple cli tool for trying out different nodejs modules.

trymodule demo

Installation

npm install -g trymodule

Usage

trymodule colors

Downloads the module colors if needed, and starts a nodejs REPL with colors loaded in the current scope, ready for you to use.

trymodule colors lodash

Same as above but with many packages in one go!

trymodule colors=c lodash=l

Assign packages to custom variable names.

trymodule --clear

Removes the directory where trymodules stores the node modules. Removes TRYMODULE_PATH + '/node_modules'

Configuration

There are a couple of environment variables you can use to customize trymodule.

TRYMODULE_PATH for setting the path of where modules are stored. By default this is $HOME/.trymodule or $USERPROFILE/.trymodule

TRYMODULE_NONINTERACTIVE for making trymodule not fire up the repl in the end. This is useful if you want to just install some packages for future use. By default this is undefined. Setting it to any value would make trymodule non-interactive.

TRYMODULE_HISTORY_PATH for changing where to save the repl history. Should be pointing to a user write-able file. Defaults to $TRYMODULE_PATH/repl_history

You can set the environment variables for one session with export TRYMODULE_PATH=/usr/bin/trymodule or for just one time by doing TRYMOUDLE_PATH=/usr/bin/trymodule trymodule colors.

Support / Help

If you have any questions, open a Github issue here: github.com/VictorBjelkholm/trymodule/issues/new

or feel free to contact me on Twitter here: @VictorBjelkholm

Inspiration

Inspiration comes from a leiningen plugin called lein-try that allows you to try out clojure libraries without having to declare them in an existing project. Thanks to @rkneufeld for the inspiration!

License

The MIT License (MIT)

Copyright (c) 2016 Victor Bjelkholm

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Allow multiple packages

    Allow multiple packages

    kinsi55 suggested on reddit that we could download and use multiple packages in one line. Something like this: trymodule lodash underscore and they would be assigned to lodash and underscore

    opened by victorb 6
  • support Promises

    support Promises

    Thanks for a great package to try out libraries (and the ipfs work)!

    Several packages return Promise objects but when trying out libraries it would be nice to see what the Promise resolved to rather than just knowing that a Promise was returned. For example, if you run trymodule octokat and then enter (new octokat()).zen.read() in the REPL (which executes GET https://api.github.com/zen ) you get the following:

    > (new octokat()).zen.read()
    Promise { <pending> }
    > 
    

    With this code change you instead get the resolved Promise:

    > (new octokat()).zen.read()
    Returned a Promise. waiting for result...
    'It\'s not fully shipped until it\'s fast.'
    >
    

    It seems libraries like es6-promise are still being actively downloaded (~250k/day) so I also included support for that

    Btw, I stumbled upon this great package from http://www.thedotpost.com/2016/12/zeke-sikelianos-navigating-javascript-userland (thanks @zeke !)

    opened by philschatz 4
  • Assign module to a custom variable in REPL

    Assign module to a custom variable in REPL

    Hey all 👋

    I saw the discussion in #17 and decided to jump in.

    Let's talk about these changes, and hopefully get them merged.

    Changes:

    • Implement custom variable feature
    • flags and packages arrays to make adding more features a little easier
    • return statements added to block-body arrow functions: per MDN, "The block body form doesn't automatically return a value. You need to use an explicit return statement."
    • Packages are passed around as tuples before they're resolved in index.js, so we can keep track of both what the module's name is and what the user wants to assign it to.
    • hasFlag and makeVariableFriendly functions were added.
    • A test for the new functionality was added.
    opened by shockey 4
  • use a different variable name for lodash in readme example

    use a different variable name for lodash in readme example

    Using _ doesn't work on newer versions of node. See https://github.com/nodejs/node/issues/5431

    ❯ node -v   
    v6.4.0
    
    ~/Desktop master*
    ❯ trymodule lodash=_
    Gonna start a REPL with packages installed and loaded for you
    'lodash' was already installed since before!
    Package 'lodash' was loaded and assigned to '_' in the current scope
    REPL started...
    > Expression assignment to _ now disabled.
    
    opened by zeke 2
  • Be able to set a specific variable name

    Be able to set a specific variable name

    Maybe someone is used to calling lodash as _ in their code, we should allow them to specify this when starting trymodule.

    Example

    # trymodule [email protected]=_ [email protected]=underscorejs
    Package 'lodash' was loaded and assigned to '_' in the current scope
    Package 'underscorejs' was loaded and assigned to 'underscorejs' in the current scope
    

    This was first brought up in https://github.com/VictorBjelkholm/trymodule/issues/13

    enhancement help wanted 
    opened by victorb 2
  • Use global regex to replace unwanted characters

    Use global regex to replace unwanted characters

    This is a small change for replace unwanted characters of the package name, also ensures to replace all the occurrences of the string, so, having this name "abc-de.ab--.cde-":

    Before "abc_de_ab--.cde-" Now "abc_de_ab___cde_"

    Thanks for the module!

    opened by zzarcon 2
  • How do I get specific functions of a module?

    How do I get specific functions of a module?

    hi! I want to try out node-jira module which requires me to import the module like this JiraApi = require('jira').JiraApi;

    I am unable to figure out how to run the same in trymodule node-jira.

    opened by ghost 1
  • Should persist history between sessions

    Should persist history between sessions

    I'm trying to get trymodule to persist the history between sessions but not sure what I'm doing wrong. I've opened a issue in nodejs/node, asking for help.

    https://github.com/nodejs/node/issues/5730

    opened by victorb 1
  • Use os.homedir() instead of process.env.HOME || process.env.USERPROFILE

    Use os.homedir() instead of process.env.HOME || process.env.USERPROFILE

    https://github.com/VictorBjelkholm/trymodule/blob/2030806d790213d426456959fdc7a69773a4c6f7/index.js#L9 Use os.homedir().

    From https://github.com/sindresorhus/awesome-nodejs/pull/477#event-606502245

    enhancement help wanted 
    opened by victorb 0
  • REPL cannot start due to error with loading history

    REPL cannot start due to error with loading history

    I get this error when I try to run anything e.g. trymodule lodash:

    Gonna start a REPL with packages installed and loaded for you
    Couldn't find 'lodash' locally, gonna download it now
    [email protected] .trymodule/node_modules/lodash
    Package 'lodash' was loaded and assigned to 'l' in the current scope
    REPL started...
      /usr/local/lib/node_modules/trymodule/node_modules/repl.history/index.js:19
      repl.rli.addListener('line', function(code) {
               ^
    
    TypeError: Cannot read property 'addListener' of undefined
        at module.exports (/usr/local/lib/node_modules/trymodule/node_modules/repl.history/index.js:19:12)
        at /usr/local/lib/node_modules/trymodule/cli.js:72:7
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (node:internal/process/task_queues:94:5)
    

    I've done basic clean up steps i.e. uninstall trymodule and delete the ~/.trymodule/ folder (or trymodule --clear).

    I don't understand why it fails here.

    opened by lordlycastle 4
  • Multiple vulnerabilities in outdated packages

    Multiple vulnerabilities in outdated packages

    Currently trymodule contains 41 vulnerabilities (35 moderate, 6 high) due to not updated packages. @victorb please update packages.

    List of outdated packages with vulnerabilities:

    Severity: Moderate Type: ReDoS
    Package brace-expansion
    Patched in >=1.1.7
    Dependency of trymodule Path trymodule > npmi > npm > fs-vacuum > rimraf > glob > minimatch > brace-expansion
    Path trymodule > npmi > npm > fstream-npm > fstream-ignore > minimatch > brace-expansion
    Path trymodule > npmi > npm > node-gyp > fstream > rimraf > glob > minimatch > brace-expansion
    More info https://nodesecurity.io/advisories/338

    Severity: Moderate
    Type: Prototype pollution Package hoek
    Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
    Dependency of trymodule Path trymodule > npmi > npm > node-gyp > request > hawk > boom > hoek Path trymodule > npmi > npm > node-gyp > request > hawk > cryptiles > boom > hoek
    Path trymodule > npmi > npm > node-gyp > request > hawk > hoek Path trymodule > npmi > npm > node-gyp > request > hawk > sntp > hoek
    Path trymodule > npmi > npm > npm-registry-client > request > hawk > boom > hoek
    Path trymodule > npmi > npm > npm-registry-client > request > hawk > cryptiles > boom > hoek
    Path trymodule > npmi > npm > npm-registry-client > request > hawk > hoek
    Path trymodule > npmi > npm > npm-registry-client > request > hawk > sntp > hoek
    Path trymodule > npmi > npm > request > hawk > boom > hoek Path trymodule > npmi > npm > request > hawk > cryptiles > boom > hoek
    Path trymodule > npmi > npm > request > hawk > hoek Path trymodule > npmi > npm > request > hawk > sntp > hoek More info https://nodesecurity.io/advisories/566

    Severity: High
    Type: Regular Expression Denial of Service
    Package sshpk Patched in >=1.13.2 < 1.14.0 || >=1.14.1 Dependency of trymodule Path trymodule > npmi > npm > node-gyp > request > http-signature > sshpk
    Path trymodule > npmi > npm > npm-registry-client > request > http-signature > sshpk
    Path trymodule > npmi > npm > request > http-signature > sshpk More info https://nodesecurity.io/advisories/606

    Severity: High
    Type: Regular Expression Denial of Service Package tough-cookie
    Patched in >=2.3.3 Dependency of trymodule Path trymodule > npmi > npm > node-gyp > request > tough-cookie Path trymodule > npmi > npm > npm-registry-client > request > tough-cookie
    Path trymodule > npmi > npm > request > tough-cookie More info https://nodesecurity.io/advisories/525

    Severity: Moderate
    Type: Memory Exposure Package tunnel-agent Patched in >=0.6.0 Dependency of trymodule Path trymodule > npmi > npm > node-gyp > request > tunnel-agent Path trymodule > npmi > npm > npm-registry-client > request > tunnel-agent
    Path trymodule > npmi > npm > request > tunnel-agent More info https://nodesecurity.io/advisories/598

    Severity: Moderate
    Type: Out-of-bounds Read Package stringstream Patched in >=0.0.6 Dependency of trymodule Path trymodule > npmi > npm > node-gyp > request > stringstream Path trymodule > npmi > npm > npm-registry-client > request > stringstream Path trymodule > npmi > npm > request > stringstream More info https://nodesecurity.io/advisories/664

    opened by pumano 0
  • fix promise detection

    fix promise detection

    Functions are objects and are valid thenables:

    "promise" is an object or function with a then method whose behavior conforms to this specification. [1]

    This PR uses is-promise to detect promises in a spec-compliant way.

    [1] https://promisesaplus.com/#terminology

    opened by chocolateboy 0
  • allow assignment to underscore (_) without a warning (closes #22)

    allow assignment to underscore (_) without a warning (closes #22)

    This uses the same approach as n_ (@borisdiakur++) to ensure that _ can safely be assigned and reassigned without:

    Tested on:

    • v4.0.0
    • v4.2.1
    • v4.8.1
    • v6.10.1
    • v7.8.0
    opened by chocolateboy 0
  • Idea: trymodule .

    Idea: trymodule .

    Hey @VictorBjelkholm. I love this module!

    It would be cool to be able to run trymodule . or trymodule some/dir to load a REPL for a given directory, using the name of the directory as the name of required module:

    cd projects/foo
    trymodule .
    

    Then in the repl, foo would be set to the value of require('.')

    opened by zeke 0
Releases(1.3.0)
Owner
Victor Bjelkholm
Victor Bjelkholm
NodeJS Framework for Interactive CLIs

Cliffy - A Framework For Interactive CLIs Cliffy is a simple, powerful utility for making interactive command line interfaces. Cliffy is run as a REPL

Drew Youngwerth 318 Dec 30, 2022
Tasks Management CLI application with Nodejs, Mongodb, inquirer.js, and commander

Tasks CLI Tasks CLI is a program to manage your tasks in a database using terminal or console. This is a sample project for beginners Requirements Nod

Fazt Web 9 Nov 17, 2022
NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids

Magic CLI ?? ?? NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids Installing Install dependencie

Lucas 3 Sep 27, 2022
nact ⇒ node.js + actors ⇒ your services have never been so µ

nact ⇒ node.js + actors your services have never been so µ Any and all feedback, comments and suggestions are welcome. Please open an issue if you fin

Natalie Cuthbert 1k Dec 28, 2022
✍ It has never been so easy to document your things!

Docz makes it easy to write and publish beautiful interactive documentation for your code. Create MDX files showcasing your code and Docz turns them i

Docz 23.1k Jan 9, 2023
As my pepper bot's users have been requesting me for its source code

Discord Bot As my pepper bot's users have been requesting me for its source code. Here it is. Enjoy! ! Invite Pepper ( See how it works ) To invite th

Husnul Jahneer 4 Nov 6, 2022
A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Jean Rodríguez 7 Sep 13, 2022
It's a repository to studies. Its idea is to learn about Nx and its plugins.

StudyingNx This project was generated using Nx. ?? Smart, Fast and Extensible Build System Adding capabilities to your workspace Nx supports many plug

Open-ish 4 May 13, 2022
Can see everything, beware of its omniscience, kneel before its greatness.

Can see everything, beware of its omniscience, kneel before its greatness. Summary Presentation Installation Removing Credits Presentation Main goal T

Duc Justin 3 Sep 30, 2022
Github Actions and Workflows that make maintaining Magento2 projects and modules easier.

Magento 2 GitHub Actions Opinionated Github Actions and Workflows to make building, testing, and maintaining Magento 2 Modules easier. README if you a

Graycore, LLC 35 Dec 21, 2022
This project is based on the Awesome Books app repo, refactored with ES6 and organized with modules. The purpose of this project is to learn functionality organization using JavaScript modules.

Awesome Books with ES6 and modules A basic app project built with HTML, CSS and JS ES6 to keep track of awesome books. Built With HTML/CSS and JS best

Karla Delgado 10 Aug 27, 2022
Simple realtime chat application made by NodeJS, Express, Socket.io and Vanilla Javascript. This project is made to discover socket.io and understand its basic features.

LearnByChat App Simple realtime chat application made with NodeJS, Express, Socket.io and Vanilla Javascript. This project is made to discover socket.

Ayoub Saouidi 1 Dec 19, 2021
MERN stack application which serves as an online map journal where users can mark and rate the places they've been to.

PlaceRate PlaceRate is a MERN stack application which serves as an online map journal where users can mark and rate the places they've been to. You ca

Yuvraj Virdi 0 May 17, 2022
Been interested, studying, and developing blockchain security with a Zero Knowledge Proof (ZKP) and create a prototype on the current issue with Philippine's upcoming election. 📥

Implementation of Zero Knowledge Proofs in Cryptographic Voting ?? Reference: Cryptographic Voting – A Gentle Introduction Overview ????‍?? The main i

Karl Joseph Saycon 2 Apr 11, 2022
Detect if a contract has been deployed in the latest (or predefined) block from an address that was previously funded through Tornado.Cash.

??️‍♂️ TORN Detector Detect if a contract has been deployed in the latest (or predefined) block from an address that was previously funded through Tor

Pascal Marco Caversaccio 14 Dec 24, 2022
A daily activity tracking application that helps to organize your daily tasks and keep track of tasks that have been completed, or yet to be completed.

To-Do-List This is my To-Do List project in the Microverse curriculum. Built With HTML CSS Javascript (Webpack) GitHub Live Demo Live Demo Link Gettin

Hammed Adisa 8 May 7, 2022
A Technical Blogging Website that utilizes Notion as a CMS for ease of modification with the help of the notion-API & whose content has been rendered with next-js and react-notion-x

GDSC MCE Blogs This repo is what GDSC MCE uses to power their blogging website gdsc-mce-blogs. It uses Notion as a CMS, fetching content from Notion a

null 7 Dec 16, 2022