home
github
npm
10 Jul 2024

node-x

node-x is a script launcher for node.js
so where before we would use
node server.js
now the following syntax can be used
node-x server.js
it works by maintaining a list directories for node-x to access, then files from those directories can be run easily
when a directory has been added to node-x, additional features can be used, such as
execute execute a script in that directory from anywhere
multiple directories create lists of directories then run scripts from those directories
aliases long commands that are used often can be aliased by short words
cat print the contents of a file to the console
findstr search in files for a word or list of words
find find a file
ls easily list the contents of a directory
node-x supports multiple configurations that can be switched in and out easily
a node-x configuration consists of a list of directories and a list of aliases
configurations are written to the node-x.js file

install

npm global installation

recommended way to install
npm install node-x -g
node-x can then be run from anywhere on the file system by entering on the command line
node-x -version
note : windows powershell users
running powershell scripts are disabled by default
to get the script to run normally in powershell users will have to delete node-x.ps1 file from the default npm script installation directory this is usually
c:/users/<user>/AppData/Roaming/npm/
or launch the program using
node-x.cmd -version
see also alternative installation methods below

uninstall

npm global installation

npm uninstall http-file-upload -g

operation

file selection

file selection is matched if the absolute filename ends with the given wildcard pattern
hence, given a file with absolute filename /work/tmp/script.js the following would match
node-x script.js
node-x script*
node-x *ipt.js
node-x ?crip?.js
if multiple files match the given pattern they will all be listed, a pattern must be given to uniquely identify a file
given 2 files with absolute filenames
/work/dir1/script.js
/work/dir2/script.js
the following command would match both of them
node-x script.js
the wildcard pattern must be expanded to uniquely identify which file to execute
node-x dir1/script.js or node-x 1/script.js

file extensions

files can be specified with or without file extensions
supported automatic file extensions are .js .mjs .cjs
ie, script script.js can be called either as node-x script.js or node-x script

command line parameters

node-x supports the following command line parameters
the parameters can be specified in any order, with or without the dash or with a double dash
add <dir> add <dir> to the list,
rem
<dir>
remove directory <dir> from list, if <dir> is not given the current directory is used
list | dirs display the current list of directories
files display all files currently accessible
find <file> search of files for <file>
regex <exp> search the directory list for files that match the regex
cat <file> display the contents of <file>
findstr <valueN> search for <value> within file list, multiple values supported
clear clear all configuration data
ls <dir> display the contents of directory <dir>
del <file> delete <file>
alias <name> <value> create alias <name> with <value>, value can be more than one space seperated values
alias-rem <name> remove alias <name>
config <name> switch to configuration <name>, without <name> lists available configurations
config-add <name> add new default configuration <name>
config-rem <name> remove configuration <name>
config-info <name> display configuration info for <name>
config-cur display the current configuration information
config-rename <name> rename the current configuration
h | help display command line help
v | version display the current program version

example useage

execute script

execute script script.js
node-x script.js

add directory

add the directory /work/scripts/ to the current configuration list
node-x add /work/scripts/
add the current directory to the current list
node-x add

remove directory

remove the directory /work/scripts/ to the current configuration list
node-x rem /work/scripts/
remove the current directory to the current list
node-x rem

list the current directory list

node-x list

list files

node-x files

find file

node-x find script.js

display file contents

node-x cat script.js

find text within file

node-x findstr <searchN>

alias a long command with a short word

a long command can be aliased by a short word, the alias is created first
to alias the command server.js -p 4000 -cwd /work/www/ -ip 127.0.0.2
node-x alias server server.js -p 4000 -cwd /work/www/ -ip 127.0.0.2
the command can then be run by using the alias
node-x server

remove an alias

remove a previously created alias
node-x alias-rem server

change configurations

to change configurations
node-x config config-1

list current configurations

list all current configurations
node-x config

add configuration

to add and change to the newly created configuration
node-x config-add config-2

remove configuration

to remove a previously created configuration
node-x config-rem config-2

display configuration information

to display configuration information, dir list and aliases
node-x config-info config-1

display current configuration

display current configuration information, dir list and aliases
node-x config-cur

rename current configuration

rename the current configuration
node-x config-rename test-configuration

clear all configuration data

clear all configuration data
node-x clear

alternate installation methods

feedback

stackoverflow chat

im usually available in the stackoverflow javascript chat room user matt, come and say hi, id love to hear from you
page title designed with
textstudio.com