From the course: Cloud Native Development with Node.js, Docker, and Kubernetes

Creating your Node.js app

From the course: Cloud Native Development with Node.js, Docker, and Kubernetes

Start my 1-month free trial

Creating your Node.js app

- [Instructor] Before we can make an app cloud native, and deploy it to Kubernetes, we first need an app. There are a number of frameworks available that we could use including Koa, hapi, Fastify, and LoopBack. For this course we'll use Express.js, which is currently the most popular, and which describes itself as a fast, unopinionated, minimalist web framework. The Express website provides a Getting started guide, and this includes an Express generator. The Express generator can be used to build a template application from which you can then do your development. You can install that using npm install express-generator -g. This does a global install and sets up the Express CLI. From the Express CLI you can use the -h option for help to see what options are available to you. We're just going to build default application with the default view at template engine installed and to do that we just use express myapp, and that creates an application called myapp in the myapp directory. Now that's happened we can go into that directory and look at the files that it's generated for us using ls to list the directory. This shows us that it's given us a complete Node.js application including a package.json file. And looking at that file, it can show us that it set up the full set of dependencies, and that it starts the application by running node ./bin/www as its start script. We can now type npm install to install our application, and this pulls down all of the dependencies which have been listed in the package.json file, and then we can run npm start which calls that start script. So effectively this is doing node ./bin/www. Now that's happened we can go to our browser, open it to port 3000, and see our running application. And there we go. It shows us our application is running, and it reports Express, Welcome to Express. Finally, if we go back to our terminal, we can hit Control + C to stop the running application, and now we have something that is ready to be worked on and deployed to the cloud.

Contents