[AwesomeProjects] How to install Node.js on Raspberry Pi 2 and create a simple Webserver to Host a static Website

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:
formatting link
[image: >
formatting link
> > 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 > >
formatting link

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: > >
formatting link
> this other tutorial

formatting link

--


news.alt119.net / www.alt119.net 
...
Reply to
Eduardo M.
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.