Share:
For example, you have some AJAX requests in your front-end. And you'll probably get errors during testing. Why is that so? It's all about security reasons of an access to your local file system through javascript requests. In other words, someone can get to your secret recipes of success. Current versions of browsers use CORS technique (Cross-origin resource sharing), which directly play a role of guard, but also cause error messages.
Obviously, you must use real server topography for successfully testing your scripts . And there are some options for that. First of all, you just can upload your files directly to your server and check their efficiency. But also you can setup local version of server.
Let's pay our attention to the last option. The process of setting up local server can be a tiresome and lingering. Furthermore, it's not always a rational path to have a large amount of operations just to take a look on a small response of a small script.
And here we are! There is decision. It's not unique, but very simple - zero-configuration command-line http server.
> http-server
This small string let you turn on http-server on your local machine. But it's powerful enough for your production. If you have not NPM, you can get it here - https://nodejs.org/en/download/. Next step is installation:
> npm http-server install -g
You should install it globally -g so it may be run right from the command line then.
Done! Go to your working directory and write a command
> http-server
Now open your browser, go to localhost:8080 and have fun with your application. Default path for server is ./public folder, if it exists, or ./ otherwise. Default port is 8080, but you can change it if you need.
> http-server [path] [options]
-p Port to use (defaults to 8080)
-a Address to use (defaults to 0.0.0.0)
-e or --ext Default file extension if none supplied (defaults to 'html')
-o Open browser window after starting the server
-h or --help Print this list and exit.
Other config settings you can find here: https://github.com/indexzero/http-server, https://www.npmjs.com/package/http-server