1

I want to write a batch script (build.sh) to install dependencies, run front end, and run back end at the same time

package.json file

"scripts": {
  "dev": "nodemon server.js",
  "client": "cd client && npm start",
  "start": "concurrently \"npm run dev\" \"npm run client\" ",
  "build": "chmod +x ./build.sh"
},

build.sh file

#!/bin/bash

npm run build

npm i aws-sdk body-parser concurrently cors dotenv express joi mongoose multer multer-s3 

cd client
npm i axios bootstrap config jquery node-modules react react-bootstrap react-dom react-scripts redux redux-form redux-thunk web-vitals 
cd ..

npm start

I'm not sure what I'm missing to have it run properly? Thanks in advance!

When I type $ npm build, into the command line (in the app's directory of course) I get this:

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /Users/SebastianRusso/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

[email protected] /usr/local/lib/node_modules/npm

Did you mean this?
    rebuild
Sebastians-MacBook-Pro:profile-app-server SebastianRusso$ npm buildd

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /Users/SebastianRusso/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

[email protected] /usr/local/lib/node_modules/npm

Did you mean this?
    rebuild
3
  • npm run-script build? Commented Nov 29, 2020 at 17:50
  • Just to be clear, your error message doesn't appear to come from typing $ npm build, but npm build. $ is not part of the command, just a convention for representing the user's shell prompt. Commented Nov 29, 2020 at 18:21
  • Yes, if i wasn't clear^ that's what I meant to. Thanks Commented Nov 29, 2020 at 18:28

2 Answers 2

1

build is not a valid CLI command for npm. To run the build script defined in the package.json, do $ npm run build.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks, $ npm run build, does make it run. but it only prints: "> chmod +x ./build.sh" rather than load the dependancies and run the app.
It runs the associated command you've specified in package.json. What did you expect it to do?
Sure, that's because all you've asked it to do is add executable permissions to the file build.sh. If you want to run that script as well, replace the definition of build in the package.json with chmod +x ./build.sh && ./build.sh
interesting, and thank you that worked. i'm curious as to why you'd have to add "&& ./build.sh" a second time. regardless, it works, so thanks again.
0
"build": "chmod +x ./build.sh"

should be:

"build": "./build.sh"

chmod +x just makes the build.sh file executable, it doesn't actually run it.

Then to run the build command from npm you have to use npm run build like the other answer said.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.