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

node-nc

v1.0.0

Published

Node console. A rails inspired command line for node.

Downloads

1,573

Readme

.  .       .        ,-.                 .
|\ |       |       /                    |
| \| ,-. ,-| ,-.   |    ,-. ;-. ,-. ,-. | ,-.
|  | | | | | |-'   \    | | | | `-. | | | |-'
'  ' `-' `-' `-'    `-' `-' ' ' `-' `-' ' `-'

About

Greenkeeper badge

Have you missed a good repl while developing a Node.js project?
Use node-nc to easily configure your project's console (similar to rails c).
Just type node-nc in any of your project's folder.

Installation

$ npm install -g node-nc

Usage

$ node-nc # or nc
nc > reload(false) // reloads all global files without reload nc by default
nc > .reload false // same as above
nc > $module$ // the path that is required when using module
nc > module   // the module

It is intended to be used inside Node.js projects.
The nc command can also be invoked from a projects subfolder.
If used outside a project it will not globalize any file and will save history to ~/.nc_history (~/${config.historyFileName}).

nc

Details

This module extends Node.js basic repl functionality:

  • Makes all js files global
  • Makes all modules included in package.json global
  • Awaits promises (experimental).
  • Writes commands to a local history file.
  • Configurable behavior using env variables or a nc.js file.
  • Suggests params for functions and methods (experimental).

Configuration

const defaultConf = {
  useGlobal: false, // Repl useGlobal. If set to true all globals will be inside nc namespace.
  useAsync: false, // Experimental use of await in repl for node versions that don't support top level await.
  globalizeFiles: true, // Make all project files global.
  globalizeDependencies: true, // Globalize projects dependencies.
  useNcFile: true, // Use nc.js file if it exists.
  usePackageFile: true, // Use package file to determine prompt, root folter and dependencies.
  writeHistoryFile: true, // Write all commands to a file.
  historyFileName: '.nc_history', // The history filename. An absolute path can also be given.
  suggestParams: true // Experimental suggestion of params when calling a function
};

Configuration can be overwitten

  • by env variables:

    NC_USE_GLOBAL, NC_USE_ASYNC, NC_GLOBALIZE_FILES, NC_GLOBALIZE_DEPENDENCIES, NC_USE_NC_FILE, NC_USE_PACKAGE_FILE, NC_WRITE_HISTORY_FILE, NC_HISTORY_FILE_NAME, NC_SUGGEST_PARAMS or

  • by using an nc.js file. This file can also be used to make some project initializations Eg. connect to a database, declare some global vars etc. In nc.js a method setConfig(options) is available to overwrite the default configurations. Note that NC_USE_NC_FILE env variable must not be false.

    Example of a simple nc.js file:

    
      // overwrite useGlobal
      setConfig({ useGlobal:true });.
    
      // connect to db
      mongoose.connect(mongooseDb, options, function (err, data) {});

Using await

If you have a very complicated expression (many nested expresssions) it is better to split it in two:

// Bad
await Compicated-Epression

// Good
const promise = Complicated-expression
await promise;

This way await will work as expected.

Function Parameter Suggestions

When you type a parenthesis repl will try to figure out if the previous expression is a function and suggest its parameters.

Build in profiler

Test a function's performance using the buildin profiler. The function can return a promise.

node-nc> profiler(() => fib(10))
Function ()=> fib(10) ran 40,770 times in 995.99 ms

node-nc> await profiler(() => fib(20))
Function ()=> fib(20) ran 328 times in 942.71 ms

node-nc> await profiler(() => Promise.resolve(true), () => {})
Run function ()=> Promise.resolve(true) 171,784 times in 1020.95 ms
Run function ()=>{} 111,795,737 times in 1007.90 ms