Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.raspberry-pi > #9739
| From | Eduardo M. <internetado@alt119.net.invalid> |
|---|---|
| Newsgroups | comp.sys.raspberry-pi |
| Subject | [AwesomeProjects] How to install Node.js on Raspberry Pi 2 and create a simple Webserver to Host a static Website |
| Date | 2015-10-01 15:46 -0300 |
| Organization | alt119 - http://www.alt119.net |
| Message-ID | <mujkfs.218.1@news.alt119.net> (permalink) |
How to install Node.js on Raspberry Pi 2 and create a simple Webserver to Host a static Website > When you work to build a modern website based only on HTML5 and > Javascript, you don't need complex configurations to verify how the > end user will display the web site. A simple web server serving > static files is the fastest and easiest solution, in this guide we > will learn how to install Node.js and create a simple web server to > use for our work. Node.js is a runtime environment for developing > server-side web applications. In simple words, the Node.js platform > makes it possible to run JavaScript programs on a server and also on > your Raspberry Pi 2. > > [link: http://i.imgur.com/BAFunzW.png] [image: > http://i.imgur.com/BAFunzW.png] > > First of all, please run the following command in a shell or > terminal > > sudo apt-get update > > Please wait! This command can be very slow, it downloads the package > lists from the repositories and "updates" them to get information on > the newest versions of packages and their dependencies. > > Remove a program with similar name to node.js (it creates conflicts, > so better remove it) > > sudo apt-get --purge remove node > > To install Node.js run the commands > > sudo apt-get install nodejs > sudo apt-get install npm > > Nice job! You have sucessfully installed nodejs and npm in your > Raspberry Pi 2. You can see the version currently being used by the > shell by typing: > > node -v > > If nothing happens and you have the error node: No such file or > directory create a symlink with the command > > sudo ln -s /usr/bin/nodejs /usr/sbin/node > > Create a folder called /var/www/ and navigate to that folder, it > will be our work directory. > > sudo mkdir /var/www > cd /var/www > > We are ready to start coding! We will create a simple Webserver to > host static website. Install the dependencies > > npm install --save compression connect http serve-static > > Create a folder called httpdocs, this folder will cointain your HTML > file, images and js code you want to host. > > sudo mkdir /var/www/httpdocs > > For example create a file index.html > > Create in /var/www a file named server.js and put this code inside: > > or you can download the file > > wget > > https://gist.githubusercontent.com/orfeomorello/704f8639a5afcf50871f/raw/2ca571e41e9bc4c2fd12578293bdcd08eda51a34/server.js If > you followed all the steps, typing the ls command you can see this > dicrectory structure > > httpdocs node_modules server.js > > To start the web server, execute the script with the command > > node server.js > > This will create a local webserver running on port 8181, if you > write this web addess in your browser > http://localhost:8181/index.html you will view your website running > (remember to put your files in /var/www/httpdocs folder). To stop > running the server press ctrl + c > > Do you want to make available your website directly on the Internet? > Follow [link: > > http://www.awesomeprojects.xyz/2015/09/performing-port-forwarding-on-your-wifi.html] > this other tutorial http://www.awesomeprojects.xyz/2015/09/how-to-install-nodejs-on-raspberry-pi-2.html -- news.alt119.net / www.alt119.net ...
Back to comp.sys.raspberry-pi | Previous | Next | Find similar | Unroll thread
[AwesomeProjects] How to install Node.js on Raspberry Pi 2 and create a simple Webserver to Host a static Website Eduardo M. <internetado@alt119.net.invalid> - 2015-10-01 15:46 -0300
csiph-web