How to Set Up a Basic Express Project
Zenva
ACCESS the FULL COURSE here: https://academy.zenva.com/product/full-stack-web-development-mini-degree/?zva_src=youtube-fullstackmd
TRANSCRIPT
In this video we're gonna get the project setup by setting up a basic express project and rendering a simple homepage, which is where we will begin our user interface.
So what you're gonna need for this video is the Node.js runtime installed on your machine. So make sure you head over to nodejs.org and have the LTS version installed. Use the LTS for this one. Make sure the don't install the experimental features because sometimes that causes some weird bugs that are hard to figure out. I'm going to be using the Sublime text editor, but you're welcome to use whatever you prefer. Some people prefer Atom. Some people use Visual Studio. It's up to you, but I'm gonna use Sublime. So that's it.
Let's go ahead and get started. Open up your terminal, and I'm going to cd to my desktop. Of course, you can do this wherever you do your programming work, and I'm gonna create a new directory called sample_store, and I'm going to cd into the sample_store then create a Node project by running npm init, which really just gives us a package JSON where we can set some basic configuration options for the project. So we're gonna use all the defaults for now, and that should be good to get started. So if you head over to your desktop, you should see the directory. If we open that up in our text editor, you will see the pacakge.json that we just configured, and we're good to go.
So, of course, this is gonna be a Node Express project, so that means we need to install the Express Framework, the web framework. So let's go ahead and do that. So npm install and express and then save. Don't forget to do this so that when it's done it will also be added to the package.json as a dependency, which you can now see right here, which is, of course, what we want. So let's go ahead and configure that server.js file. Oh, I did not create it yet.
So let's create a server.js file, which is where we will create the Express application. So let's go ahead and configure that file. So first thing we need to do is import Express, of course, and let's instantiate the Express app. So we will call that app, and let's setup a basic route for the homepage, which of course takes a request, response, and next argument, or a function with those arguments, excuse me, and we're gonna have this send back some very basic text confirmation, and we're gonna have this listen on port 5000, and we're gonna add a simple console log right here so that we can visually confirm on the terminal that the app is running. Great.
So now you may recall in one of our earlier videos we used nodemon to run the server, which is great because it watches the files while we work so ... https://www.youtube.com/watch?v=NDqIUD-oFLY
14524540 Bytes