Use NPM Script Generator

Enter your data below to use the NPM Script Generator

📌 Try these examples:
RESULT

Last updated

Basic Development Workflow Scripts

A standard set of npm scripts for a TypeScript web application:

{
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview",
    "test": "vitest run",
    "test:watch": "vitest",
    "lint": "eslint src --ext .ts,.tsx",
    "lint:fix": "eslint src --ext .ts,.tsx --fix",
    "format": "prettier --write src/**/*.{ts,tsx,css}",
    "typecheck": "tsc --noEmit"
  }
}

Run npm run dev to start development, npm run build to compile and bundle, npm test for a single test run. The test:watch variant is for local development.

Pre and Post Hooks

Automatically run scripts before or after another script:

{
  "scripts": {
    "prebuild": "npm run typecheck && npm run lint",
    "build": "vite build",
    "postbuild": "node scripts/generate-sitemap.js",

    "pretest": "npm run lint",
    "test": "vitest run",
    "posttest": "npm run coverage:report"
  }
}

prebuild runs automatically before build — no need to chain them manually. If prebuild fails (lint errors), the build stops. postbuild runs after a successful build.

Cross-Platform Environment Variables

Use cross-env for environment variables that work on Windows and Unix:

{
  "scripts": {
    "build:dev": "cross-env NODE_ENV=development vite build",
    "build:staging": "cross-env NODE_ENV=staging API_URL=https://staging.api.example.com vite build",
    "build:prod": "cross-env NODE_ENV=production vite build",
    "test:ci": "cross-env CI=true vitest run --reporter=junit"
  }
}
// Install cross-env
npm install --save-dev cross-env

Without cross-env, NODE_ENV=production vite build fails on Windows because Windows doesn't support the VAR=value command syntax.

Parallel Script Execution

Run multiple scripts simultaneously with concurrently:

{
  "scripts": {
    "dev": "concurrently \"npm run dev:server\" \"npm run dev:client\" \"npm run dev:types\"",
    "dev:server": "nodemon src/server/index.ts",
    "dev:client": "vite",
    "dev:types": "tsc --watch --noEmit"
  }
}
// Or with npm-run-all
{
  "scripts": {
    "dev": "run-p dev:server dev:client dev:types",
    "build": "run-s clean typecheck lint build:app",
    "build:app": "vite build"
  }
}

run-p runs scripts in parallel, run-s runs them sequentially. This is cleaner than chaining with && and works cross-platform.

Clean Build Scripts

Remove build artifacts before rebuilding:

{
  "scripts": {
    "clean": "rimraf dist .cache coverage",
    "clean:all": "rimraf dist .cache coverage node_modules",
    "prebuild": "npm run clean",
    "build": "vite build"
  }
}
// rimraf works cross-platform (like rm -rf)
npm install --save-dev rimraf

Versioning and Release Scripts

Automate version bumping and publishing:

{
  "scripts": {
    "version:patch": "npm version patch && git push && git push --tags",
    "version:minor": "npm version minor && git push && git push --tags",
    "version:major": "npm version major && git push && git push --tags",
    "release": "npm run build && npm publish --access public",
    "prerelease": "npm run test && npm run lint"
  }
}

npm version patch bumps the patch version in package.json, creates a git commit, and tags it. The push commands sync the commit and tag to the remote.

CI/CD Friendly Scripts

Scripts designed for automated pipeline environments:

{
  "scripts": {
    "ci:install": "npm ci",
    "ci:lint": "eslint src --ext .ts,.tsx --max-warnings 0",
    "ci:test": "vitest run --reporter=junit --outputFile=test-results.xml",
    "ci:build": "npm run typecheck && npm run ci:lint && npm run build",
    "ci:coverage": "vitest run --coverage --reporter=lcov"
  }
}

--max-warnings 0 makes lint fail on any warning (not just errors). --reporter=junit produces XML output that CI systems can parse for test results. npm ci installs exact versions from package-lock.json.

Documentation Generation

{
  "scripts": {
    "docs": "typedoc src/index.ts --out docs/api",
    "docs:serve": "serve docs/api",
    "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
    "changelog:first": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
  }
}

Database Scripts

{
  "scripts": {
    "db:migrate": "prisma migrate dev",
    "db:migrate:prod": "prisma migrate deploy",
    "db:seed": "ts-node prisma/seed.ts",
    "db:reset": "prisma migrate reset --force",
    "db:studio": "prisma studio",
    "db:generate": "prisma generate"
  }
}

Complete package.json Scripts Section

A production-ready scripts section for a full-stack TypeScript app:

{
  "scripts": {
    "dev": "run-p dev:server dev:client",
    "dev:server": "nodemon --exec ts-node src/server/index.ts",
    "dev:client": "vite",
    "build": "run-s clean typecheck build:server build:client",
    "build:server": "tsc -p tsconfig.server.json",
    "build:client": "vite build",
    "clean": "rimraf dist",
    "typecheck": "tsc --noEmit",
    "lint": "eslint src --ext .ts,.tsx --max-warnings 0",
    "lint:fix": "eslint src --ext .ts,.tsx --fix",
    "format": "prettier --write \"src/**/*.{ts,tsx}\"",
    "test": "vitest run",
    "test:watch": "vitest",
    "test:coverage": "vitest run --coverage",
    "db:migrate": "prisma migrate dev",
    "db:seed": "ts-node prisma/seed.ts",
    "start": "node dist/server/index.js"
  }
}

Frequently Asked Questions

Simply enter your data, click the process button, and get instant results. All processing happens in your browser for maximum privacy and security.

Yes! NPM Script Generator is completely free to use with no registration required. All processing is done client-side in your browser.

Absolutely! All processing happens locally in your browser. Your data never leaves your device, ensuring complete privacy and security.