Last active
February 18, 2019 17:22
-
-
Save gdiaz384/94d3800fd5b3465fe7010917563581cd to your computer and use it in GitHub Desktop.
setting up an HTTP static file server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Github: https://github.com/indexzero/http-server | |
#npmjs: https://www.npmjs.com/package/http-server | |
#become root | |
sudo su - | |
#install Node.js and its package manager "npm" | |
apt-get install node npm -y #Raspian | |
apt-get install node -y #Ubuntu | |
yum install nodejs npm #Fedora 21 | |
dnf install nodejs #Fedora 22 | |
#Debian | |
apt-get install curl | |
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - | |
apt-get install nodejs -y | |
#make sure both node and npm are installed and run | |
which node | |
node --version | |
which npm | |
npm --version | |
#Debian, if necessary, fix using a symbolic link | |
ln -s /usr/bin/nodejs /usr/bin/node | |
#install http-server for node | |
npm install http-server -g | |
#make sure it is exists | |
which http-server | |
#and that it runs in node | |
node http-server --help | |
node http-server & | |
#if the path searching does not work, use absolute pathing | |
/usr/bin/node http-server --help | |
/usr/bin/node http-server & | |
/usr/bin/node /usr/local/bin/http-server --help | |
/usr/bin/node /usr/local/bin/http-server & | |
#kill it | |
ps -A | grep node | |
pkill node | |
ps -A | grep node | |
#Find the true path of http-server | |
#The true path should have been listed when the symbolic was created. It can also be found by: | |
which http-server | |
#It will list it as /usr/bin/http-server, /usr/local/bin/http-server or similar, then: | |
ls -l /usr/local/bin/http-server | |
#Output: /usr/local/bin/http-server -> ../lib/node_modules/http-server/bin/http-server | |
cd /usr/local/lib/node_modules/http-server | |
#remove some unncessary data | |
nano /usr/local/lib/node_modules/http-server/node_modules/ecstatic/lib/ecstatic/show-dir/index.js | |
#1) delete the following two lines: | |
html += `${'<tr>' + | |
'<td><i class="icon '}${iconClass}"></i></td>`; | |
#2) change the line that says: | |
if (!hidePermissions) { | |
#to: | |
if (hidePermissions) { | |
#3) remove the <address> tag and contents that start on following line and ends in </address>: | |
html += `<br><address>Node.js ${ | |
#save changes and exit nano | |
CTRL+O | |
CTRL+X | |
#test configuration. Note: use absolute paths. | |
/usr/bin/nodejs /usr/local/bin/http-server /home/pi/Public -p 80 & | |
#kill it | |
ps -A | grep node | |
pkill node | |
ps -A | grep node | |
#switch back to non-root shell | |
exit | |
#add this to task scheduler | |
crontab -e #select `nano` if prompted to pick a text editor | |
@reboot sudo /usr/bin/nodejs /usr/local/bin/http-server /home/pi/Public --no-dotfiles -p 8080 | |
@daily sudo pkill node && sudo /usr/bin/nodejs /usr/local/bin/http-server /home/pi/Public --no-dotfiles -p 8080 | |
#save changes and exit | |
CTRL+O | |
CTRL+X | |
#reboot to test if autostart works | |
shutdown -r 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment