How to add two consecutive commands for console to json file?

I master node.js and NPM , I have a folder "server" in which the http server and package.json file are installed, and in it there is a folder "webdir" with a web page.

I can start the web server manually, or by specifying the path to it with the node [путь до файла, запускающего сервер] command node [путь до файла, запускающего сервер] , but I need this to happen automatically with the npm start command. And it should be launched from the "webdir" folder so that I can immediately go to my web page at localhost:8080 .

To do this, I need to write two consecutive commands to the console:
1. cd webdir
2. node [path to the file that starts the web server]

What should be the syntax in the json file for the command to enter and execute these two lines in the console?

This is how one-line working code looks like:

 "scripts": { "start": "node (...)/node_modules/http-server/bin/http-server" }, 

    1 answer 1

    One simple option is to look at the default package.json generated by the npm init command:

     { "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } 

    The && sign allows you to run one command after another if the first is executed without errors. If you use || then, the second command will be executed only if the first returns an error. This is not a feature of npm , it is a common command line operation.

    For more complex cases, you can make a sequence of commands in a separate script, and specify it already.

    • Thank you very much, for some reason, in this version, the entire script line of the command is displayed in the console, the host does not start ... - Rumata
    • While the working version is to use a semicolon, but there is a problem here: the commands that should be executed after the web server is started after it is manually turned off, apparently until the server start command is considered not completed. && - can there be a way to fix this? - Rumata
    • @MaximVelichkin Show how you write both teams through && - Vladimir Gamalyan
    • Sorry, my mistake, confused with the symbol. Everything works, thank you! True, the problem with the launch of commands after the activation of the server remained ... - Rumata
    • @MaximVelichkin If this is linux, use the & at the end of the command (after the space), then the command will be launched, but there will be no waiting for its execution. If you need a cross-platform solution, you can look at npmjs.com/package/concurrently - Vladimir Gamalyan