Npm run script frustrations

I have published a package on npm. Sometime last night I tried to install it and run it locally.

I am getting this error: missing script: new-post even though I have the script object in my package.json file.

Here is my package file:

  "name": "new-post-gatsby-starter-blog",
  "version": "1.1.5",
  "description": "create a new post in gatsby starter blog format with a simple command",
  "main": "/bin/index.js",
  "repository": {
    "type": "git",
    "url": "git+"
  "bin": {
    "new-post": "bin/new-post.js"
  "keywords": [
  "author": "Tiffany White",
  "license": "MIT",
  "bugs": {
    "url": ""
  "homepage": "",
  "devDependencies": {
    "date-fns": "^1.30.1",
    "slug": "^0.9.3",
    "slugify": "^1.3.4"
  "dependencies": {
    "shelljs": "^0.8.3"
  "scripts": {
    "new-post": "new-post"

My directory structure is a bin folder at the root of the package and inside that bin folder is the executable, new-post.js.

My executable file is basic JS:

#!/usr/bin/env node

const fs = require('fs');
const slugify = require('slug');
const dateFns = require('date-fns');
const title = process.argv[2];
const shell = require(shelljs);

if (!title) {
  throw 'a title is required!';
const slug = slugify(title.toLowerCase());
const date = dateFns.format(new Date(), 'YYYY-MM-DD');
const dir = `./src/pages/${slug}`;
if (!dir) {
  throw 'this directory does not exist!';
 date: ${date}
 title: "${title}"
  function(err) {
    if (err) {
      return console.log(err);
    console.log(`${title} was created!`);

shell.exec('node bin/new-post.js')

Not sure what I am doing wrong here.

I am on macOS 10.14.3
Using node 11.8 and the latest npm

npm doesn’t support new-post for the script property of the package.json file , see a list of supported properties here, you’d probably want something like the start property but that depends on your project, the value of it should target the exact path where new-post is, so something like \bin\new-post, if your bin folder is at the root of your project, then you’d do something like npm start or yarn start to run it.

Correction on the above, you can run arbitrary named scripts as well, what command are you using to run it, and is new-post pointing exactly to the file in the bin folder, or is it outside the bin folder? May also be a good idea to give a different name for the property and the file

Thanks! I got it working now. Took some troubleshooting but it’s live.