How can I get npm start at a different directory?

后端 未结 6 1091
野的像风
野的像风 2020-12-07 08:11

I usually cd into the app directory and then run npm start.

It is my feeling that there ought to be some way to run npm start

相关标签:
6条回答
  • 2020-12-07 08:18

    npm start --prefix path/to/your/app

    & inside package.json add the following script

    "scripts": {
       "preinstall":"cd $(pwd)"
    }
    
    0 讨论(0)
  • 2020-12-07 08:23

    Per this npm issue list, one work around could be done through npm config

    name: 'foo'
    config: { path: "baz" },
    scripts: { start: "node ./$npm_package_config_path" }
    

    Under windows, the scripts could be { start: "node ./%npm_package_config_path%" }

    Then run the command line as below

    npm start --foo:path=myapp
    
    0 讨论(0)
  • 2020-12-07 08:26

    I came here from google so it might be relevant to others: for yarn you could use:

    yarn --cwd /path/to/your/app run start 
    
    0 讨论(0)
  • 2020-12-07 08:28

    Below Command where project is a folder which contains package.json file

    npm run --prefix project ${COMMAND}
    

    is working as well. Useful in Docker based applications.

    0 讨论(0)
  • 2020-12-07 08:29

    This one-liner should work too:

    (cd /path/to/your/app && npm start)
    

    Note that the current directory will be changed to /path/to/your/app after executing this command. To preserve the working directory:

    (cd /path/to/your/app && npm start && cd -)
    

    I used this solution because a program configuration file I was editing back then didn't support specifying command line arguments.

    0 讨论(0)
  • 2020-12-07 08:31

    This one-liner should work:

    npm start --prefix path/to/your/app
    

    Corresponding doc

    0 讨论(0)
提交回复
热议问题