Creating a public directory

What is the point

The point of public directories is to hold your static infomation (such as .css, .js & .png). Everything in the defined folder is publicly avaliable for anyone to access, so make sure that you are careful with what you put in the public folder

How to registar the public folder

There is a requiremnet before you start this process, you have to create a folder and you have to know the path to it (absoulute or relative should work)

Place this line of code before you start the server

httpServer.middleware_public("public/", "/public");

What does this mean?

  • The first argument (where I type public/) is the location of the folder (this path happens to be relative).
  • The second argument (where i type /public) is the path that prefixes the files in the folder.