Skip to content

Brittany-Reid/node_code_query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Code Query (NCQ)

demo

Node Code Query (NCQ) is a tool to help Node.js developers locate, install and try out NPM packages, in a single environment.

NCQ is REPL (Read-Print-Eval Loop) environment that enables users to search for NPM packages and API code snippets. The REPL environment then allows for users to install these packages and begin programming with them. The combination of search and programming environment is what makes NCQ distinct.

Installation

1. Install Node.js and NPM

NCQ is a research project and may not be compatible with all Node.js versions. The last tested Node.js version was v14.17.0.

Hint: Use nvm to install node/npm. Install nvm. Then, run the command nvm install <version>

2. Clone this repository

git clone https://github.com/damorimRG/node_code_query.git

3. Change to the corresponding directory.

cd node_code_query

4. Install

npm install

This step may take some time. In addition to installing dependencies, it runs a setup script and downloads a snapshot of the NPM data to create a local database (for efficiency).

You can now use npm start to run the program.

5. Globally install the ncq command (optional).

To use the ncq command, and to run ncq from any location, you can install this repository globally.

npm install -g

Dataset

The dataset will automatically be downloaded when installing NCQ, you do not need to manually download and extract it, however, the dataset is also made available at https://zenodo.org/record/5094598

Keybindings

REPL mode

KeyBinding Command Details
return Submit
escape or f10 Cancel
delete Delete Character
meta + delete Delete word ctrl + w also works.
ctrl + delete Delete line ctrl + u also works.
ctrl + Move to line start
ctrl + Move to line end
meta + Previous Word meta + b also works.
meta + Next word meta + f also works.
Cursor Line Up
Cursor Line Down
f4 Newline
f5 Clear Clears currently entered input.
f6 Editor Enter editor mode.
f9 Save

Editor mode

KeyBinding Command Details
return Newline
f9 or ctrl + s Save

Example

Let us consider the scenario where the developer wants to read a file (e.g., "/etc/passwd") and print its contents on screen. Here is how NCQ can help:

1. Start NCQ

Run the ncq command, or if you didn't install the tool globally, npm start within the root drectory. Your screen should look like this.

ncq command

2. Create a new REPL

Type the repl command to create an environment where you can play with different examples. The name REPL refers to "Read Eval Print Loop". The tool will present the REPL load menu, if this is the first use, you will be prompted to name a new REPL project instead. When you are done, the REPL will start, initializing your project and loading in the code snippet database. This may take some time.

repl command

The square brackets in the command prompt indicate that you successfully created a node repl, i.e., you can run any node.js code from the prompt now. However, you do not have any library installed!

3. Search for packages

Type .packages read text file to see an interactive list of packages from NPM you can install for the task "read text file".

packages command

In this case, we select the first package using enter. This will ask us if we would like to install. Press enter to install the package.

packages command

Your screen should now look like this, indicating the package was installed successfully:

packages command

4. Search for code snippets

Use the .samples command to see code snippets for the currently installed packages. You can also search for the specific package using .samples @jcbuisson/readlinesync. You should see a code snippet on your screen, you can navigate these with F2 and F3.

packages command

5. Run the example

The above example generates an iteratable set of lines from a file, then prints each line. Press enter to run the code. You will see an error that filePath is undefined.

6. Modify the example

Rerun the .samples command to see the previous example. This time, add a new line at the beginning. Remember that the current working directory is the REPL project directory, so you need the file to be in this directory for the following path to work:

var filePath = "etc/passwd" //new code
const readlineSync = require('@jcbuisson/readlinesync');
const lineGenerator = readlineSync(filePath);
for (let line of lineGenerator) {
  console.info(line);
}

If you recieve an error about already defined constants, use the .reset command to reset your REPL state.

You will see the contents of the file outputed on the REPL.

7. Save the project

Use the .save index.js command to save your progress. This file can be found in the repls/PROJECT directory.

Usage

You can start the NCQ CLI by using the ncq command anywhere.

ncq [options]

If you didn't install NCQ globally, you can use npm start to run the program in the repository directory.

Options
option description
-d, --debug Run in debug mode, enables extra logging.
-u, --usage Enable additional logging for user study purposes.
-r, --recordLimit <num> Limit the number of packages loaded.

Load a REPL

To load or create a new REPL, use the repl command. Once you have selected an option, NCQ will load that instance for you and you can begin programming!

REPL Commands

.packages <query>

Search for packages using the given query string, now interactively! If you select a package, you can now install it from ths menu.

.install [packages]

Given a package or list of packages, installs these in your REPL project.

.uninstall [packages]

Uninstalls a given package.

.samples [packages]

Searches for code snippets from the given packages, and shows them to you right in your REPL prompt.

.help

Show more commands.

References

Links to published work will be added here.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published