I cloned angular seed which is using node http-server and it is working perfectly using following configuration.
Command : npm start (from root of project)
Following configuration in package.json file:
"start": "http-server -a localhost -p 8000 -c-1",
Link to file
However I'm unable to start this server directly. eg: from root of the project, none of these commands work:
>  angular-seed npm http-server  
>  angular-seed node http-server
>  angular-seed http-server
Shouldn't this(http-server) be available here(root, where it got installed from)? Could someone please explain me how it is working and how I can use it directly from root of the project.
I'm sure it will work fine if I install it globally but I'm not interested in that.
A local web server is a computer that satisfies HTTP requests from the public by returning web pages. For example, a web developer may host a website and have all the files or software necessary for the website physically stored on their computer (locally) as opposed to an external web hosting company.
When you're running npm install in the project's root, it installs all of the npm dependencies into the project's node_modules directory.
If you take a look at the project's node_modules directory, you should see a directory called http-server, which holds the http-server package, and a .bin folder, which holds the executable binaries from the installed dependencies. The .bin directory should have the http-server binary (or a link to it).
So in your case, you should be able to start the http-server by running the following from your project's root directory (instead of npm start):
./node_modules/.bin/http-server -a localhost -p 8000 -c-1
This should have the same effect as running npm start.
If you're running a Bash shell, you can simplify this by adding the ./node_modules/.bin folder to your $PATH environment variable:
export PATH=./node_modules/.bin:$PATH
This will put this folder on your path, and you should be able to simply run
http-server -a localhost -p 8000 -c-1
To start server locally paste the below code in package.json and run npm start in command line.
"scripts": {
    "start": "http-server -c-1 -p 8081"
  },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With