I will explain as rudimentarily as possible how to set up a part of the file system on a local server and access it from a browser to check the operation of Web application development.
This is easy if you are in an environment where Python works. The Python standard library has a dedicated module that can be launched directly from the command line. The module names are different between Python 2 and 3, so I will explain each.
Python 2 uses Simple HTTP Server. If the port number is omitted, 8000 will be used.
$ python -m SimpleHTTPServer [port number (default is 8000)]
Python3 uses http.server.
$ python3 -m http.server [port number (default is 8000)]
Now, if you access
http: // localhost: 8000 (or just
localhost: 8000) from your browser, the server will start with the directory you started as the root. It responds to access to the directory as follows (same as the default behavior of the Apache server):
Exit the server with Ctrl-C.
Since Ruby 1.9.3, there is an httpd function in the Kernel module, which can be started from the command line as follows. The functionality is the same as Python.
$ ruby -run -e httpd . -p 8000
Actually, I didn't know this until now, and I found it in the related posts displayed immediately after uploading the first draft (I received a comment from udzura immediately after that. Thank you). But if you are a Ruby programmer, I still recommend the following method.
I'm a Ruby programmer and always use the Rack gem (Ruby before 1.9.3 is also possible). First, install Rack.
Rack is used by many Ruby frameworks. Especially if you have Ruby on Rails installed, you don't need to do this.
$ [sudo] gem install rack
sudo is required if you have Ruby installed in your system directory. (I use it) rbenv and RVM Not required if you are using the version switching tool.
Next, create a small file named
config.ru in the directory where you start the server. The contents are only the following line.
run Rack::Directory.new '.'
You are now ready. Finally, start it with the
rackup command (the following is a start example). The default port number is 9292, which is
rackup -p 8000 (example).
$ rackup [2014-04-01 14:18:53] INFO WEBrick 1.3.1 [2014-04-01 14:18:53] INFO ruby 1.9.3 (2013-06-27) [i686-linux] [2014-04-01 14:18:53] INFO WEBrick::HTTPServer#start: pid=5814 port=9292
Note that a directory listing is always returned for access to a directory (even if index.html exists, it is listed as one of the files). This should be enough for development. Once set, all you have to do is
The advantage of Rack is that you can customize it as much as you like, giving you the flexibility to write Ruby code in
config.ru for server-side programming. However, this is beyond the scope of this article, so detailed explanations are omitted.
The server side of my latest work "Weather Data Map" is also made with Rack. I would like to have the opportunity to explain Rack separately later.
I'm not very familiar with Node.js, but I know someone who makes a local server for Node.js, so I will introduce it (I also confirmed the operation). For details, please read the explanation on the following site.
I received a comment from ka_ immediately after posting. It seems that there are some node modules.
Ka_'s comments are well organized, so please see that for details.
I received a comment from kimama1997 for the PHP version, so I will add it (PHP 5.4+). See the comments section for details.
$ php -S localhost:3000
By the way, I have experience with PHP, but I am not currently using it, and I have not installed it in my current development environment.