jsenv
This tool is meant to "create a productive environment" for your nodejs scripts.
The idea is to enable you to write code like the one below without worrying about npm install
or package.json files. You can find out more details about why and how here.
#! /usr/bin/env jse
import fetch from 'node-fetch';
import html from 'cheerio';
const response = await fetch('http://example.com');
const $ = html.load(await response.text());
console.log($('p').text());
Installation
The way this works is by installing and setting up your "environment" ahead of time so you don't have to use npm init
and npm install
everytime you want to make a script.
- Step 1: clone this repository.
git clone https://github.com/VonHeikemen/jsenv
- Step 2: Next install all the packages you'll need.
You are encouraged to modify the package.json to add or remove packages as you see fit.
cd ./jsenv
npm install
- Step 3: Add
jsenv
to your PATH
npm link
Usage
After installation you'll have three different commands to run scripts.
-
jsc
: Only supports common-js modules. Doesn't have support for top-level await. You canrequire
"global" modules. -
jsm
: Only supports native es modules. Has top-level await. But you can't get "global" modules usingimport
orrequire
, instead you'll need to use the global function calleduse
. -
jse
: Supports es module syntax through a third party module loader (esm). Can also userequire
if you want to. Has top-level await support. Can use "global" modules withimport
orrequire
. What's the catch? Startup times will be slightly slower than the others.
Usage in the command line (with jse
).
jse /path/to/script.js --one arg --flag
Note: if you don't want all those executables in your
PATH
, change thebin
property inpackage.json
before usingnpm link
command.
Support
If you find this tool useful and want to support my efforts, buy me a coffee ☕.