In our server file, we want to set up this server to serve up the public folder. Now, in this case, the server.js file is not in the root of the project, which means we have to go up a directory from server to node-chat-app. Then, we have to go into the public folder. This will make it a little hard to set up the Express middleware. What we'll do is take a look at a built-in Node module that makes it really easy to convert paths.
Now, in order to show you what I'm talking about, let's go ahead and use two console.log calls:
console.log();
console.log();
The first console.log call will show us how we used to do it, and the second one will show us the better way to do it.
Inside the first console.log call, we'll provide the same path we provided for our very first Express app. We use __dirname to reference the current directory, which in this case is the server directory because the file is inside the server folder. Then, we concatenate it, /public. Now, in this case, we do not have a public folder in the server folder; the public folder and the server folder are at the exact same level, which means we need to use .. to go up a directory and then we need to go into public:
console.log(__dirname + '/../public');
console.log();
This is the old way of doing things, and if we run this from the Terminal, we can see why it looks a little weird. I'm going to run server/server.js:
nodemon server/server.js
What we get is this path, as shown in the following screenshot:

We go into the Users/Andrew/Desktop/ project folder, which is expected, then we go into server, out of server, and into public—this is absolutely unnecessary. What we'd like to do is just go from the project folder right into public, keeping a clean, cross-OS compatible path. In order to do that, we'll use a module that comes with Node called path.