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.
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>
git clone https://github.com/damorimRG/node_code_query.git
cd node_code_query
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.
To use the ncq
command, and to run ncq from any location, you can install this repository globally.
npm install -g
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
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 |
KeyBinding | Command | Details |
---|---|---|
return | Newline | |
f9 or ctrl + s | Save |
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:
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.
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.
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!
Type .packages read text file
to see an interactive list of packages from NPM you can install for the task "read text file".
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.
Your screen should now look like this, indicating the package was installed successfully:
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
.
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.
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.
Use the .save index.js
command to save your progress. This file can be found in the repls/PROJECT
directory.
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. |
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!
Search for packages using the given query string, now interactively! If you select a package, you can now install it from ths menu.
Given a package or list of packages, installs these in your REPL project.
Uninstalls a given package.
Searches for code snippets from the given packages, and shows them to you right in your REPL prompt.
Show more commands.
Links to published work will be added here.