
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
esm-executable
Advanced tools
Learn how to create an executable standalone script two different ways:
The finished package is available here:
FILE EXTENSIONS
"type": "module" in package.jsonSince we're creating a standalone script we don't have package.json we use .mjs
import * as os from "node:os";
const { username } = os.userInfo();
console.log(`Hello ${username}!`);
RUNNING WITH NODE
node hello.mjsRUNNING STANDALONE
#!/usr/bin/env node
import * as os from "node:os";
const { username } = os.userInfo();
console.log(`Hello ${username}!`);
chmod u+x hello.mjs./hello.mjsmkdir demo; cd demonpm init -ypn add lodash-es -- creates node_modules folder and package-lock.json file demo/
package.json
package-lock.json
readme.md
src/
homedir.mjs
versions.mjs
...
"type": "module",
"bin": {
"homedir": "./src/homedir.mjs",
"versions": "./src/versions.mjs"
},
...
{
"name": "esm-executable",
"version": "1.0.0",
"description": "## intro",
"main": "index.js",
"type": "module",
"bin": {
"homedir": "./src/homedir.mjs",
"versions": "./src/versions.mjs"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"lodash-es": "^4.17.21"
}
}
node ./src/homedir.mjs#!/usr/bin/env node
import { homedir } from "node:os";
console.log("Homedir: " + homedir());
node ./src/versions.mjs#!/usr/bin/env node
import { pick } from "lodash-es";
console.log(pick(process.versions, ["node", "v8", "unicode"]));
INSTALLING ON UNIX
A script such as homedir.mjs does not need to be executable on Unix because npm installs it via an executable symbolic link:
Before we publish lets check the configuration
exclude by default
node_modules
.*.swp
._*
.DS_Store
.git
.gitignore
.npmignore
.npmrc
npm-debug.log
never exclude
package.json
README.md and its variants
CHANGELOG and its variants
LICENSE, LICENCE
Here are some things we can check
npm publish --dry-runnpm packnpm link or npm install . -gnpm ls -g -- see the package-namenpm publish --access public - access only needed first timeHere's a magic trick to avoid having to use the .mjs extension throught your code.
#!/bin/sh
":"; // ; cat "$0" | node --input-type=module - $@ ; exit $?
UPDATE: I took out the snippet and it still works with this
#!/usr/bin/env node
# see the package installed
npm ls -g
...
├── esm-executable@1.0.1 -> ./../../../../../dev/code/scratch/typescript/esm-executable
...
# find the node path
which node
/Users/frankg/.nvm/versions/node/v18.15.0/bin/node
# show the executable shell scripts
ls /Users/frankg/.nvm/versions/node/v18.15.0/bin
lrwxr-xr-x 1 frankg staff 49B Sep 11 03:53 homedir -> ../lib/node_modules/esm-executable/src/homedir.js
lrwxr-xr-x 1 frankg staff 50B Sep 11 03:53 versions -> ../lib/node_modules/esm-executable/src/versions.js
FAQs
## intro
We found that esm-executable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.