-
Notifications
You must be signed in to change notification settings - Fork 18
Week 2 Notes
Now that we have a sense of how a basic server works, we're going to work on the files we serve. We won't be doing much in Node and Servi; we're going to turn our attention to HTML and CSS.
The only thing we'll need our server to do this week is serve static files. In Servi, that's basically one line of code:
serveFiles("nameOfFolder");
Where "nameOfFolder" is a folder where you'll store the HTML, CSS, and images you want to serve. For a step by step example, see the code sample in the repo.
Another difference this week is we're actually going to put our stuff on the web! That means setting up a server on a Digital Ocean account, the process for which you should have started last week. If you haven't completed the set-up yet, refer to the Digital Ocean Set-up page on this wiki.
As you'll see in the Digital Ocean tutorial, there are two ways to connect to your server: (1) The command line (aka Terminal, aka ssh
) and (2) FTP, using Cyberduck or a similar program. You'll use the command-line when you need to run code on the server side, such as we did locally in Terminal last week, with node server.js
to start the server. When you want to put files on your Digital Ocean server, you'll use FTP, which as you probably remember stands for File Transfer Protocol -- this is the program you use when you want to transfer a file from your computer to a remote location or vice versa. Cyberduck is an FTP program the way Outlook is an email program -- it's one of many available programs that let you connect to a certain protocol.
We'll use Cyberduck to upload both our server-side node (Javascript) files and the files that will be served to the browser, which will be HTML, CSS, and possibly some images. In future weeks, we'll write Javascript for the client side as well.
On your home directory on digital ocean, you will probably have one node file, likely called server.js
(though you can call it anything) and one directory to store your HTML & CSS files, likely called public
(again, the naming is up to you). Once those two things are in place, log in to your Digital Ocean server with Terminal and start the server with the command node server.js
. Make sure you are in the directory that contains the server.js file when you run the command. (Again, refer to Digital Ocean Set-up for how to log in with Terminal.)
(image here)