Author:Sebhastian, Nathan
No description
Tags
Support Statistics
¥.00 ·
0times
Text Preview (First 20 pages)
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
TABLE OF CONTENTS Preface Working Through This Book Requirements Source Code Contact Chapter 1: Introduction to Node.js The Exercise Application Computer Setup Summary Chapter 2: Your First Node.js Project Creating the Server Application Running the Server Routing in Node.js Adding Nodemon for Development Summary Chapter 3: Introduction to Express and Morgan Using Express Adding Morgan for Logging Summary Chapter 4: Using EJS Templating Engine for Views Adding EJS to Express Rendering EJS Template With Express Reuse EJS Template With Partials Summary
Page
3
Chapter 5: Using Tailwind and DaisyUI for CSS Adding Tailwind CSS to Node.js Project Using DaisyUI Summary Chapter 6: Creating a MongoDB Database Cluster MongoDB Introduction Setting Up MongoDB Atlas Cloud Welcome to Atlas Create a Cluster Security Quickstart: Set Authentication and Connection Add a New Database User Allow Your IP Address Summary Chapter 7: Integrating Mongoose to Express Mongoose Introduction Connecting to MongoDB Cluster Installing Dotenv to Read Environment Variables Summary Chapter 8: Implementing the MVC Pattern What’s an MVC Pattern? Creating the User Model Creating User Controller Creating the User View Creating the User Route Running the Routes Summary Chapter 9: Developing User Authentication Implementing Express Session Creating the AUTH_SECRET Variable Cleaning The Routes Creating the Sign Up Page Adding Font Awesome
Page
4
Updating User Controller Adding Express urlencoded Middleware Adding the Dashboard Page Summary Chapter 10: Validating Form Inputs and Displaying Messages Adding Validation to The Sign Up Process Storing Error Messages in Flash Displaying Error Messages on Sign Up Form Preserving Input Data on Sign Up Form Showing Toast Notification With Toastify Summary Chapter 11: Adding Login and Logout Functionalities Creating the Landing Page Updating the Dashboard Page Adding Login Page to Views Adding Login Function to User Controller Adding Logout Function Updating User Routes Summary Chapter 12: Protecting Routes With Middlewares Express Middleware Explained Adding Verification Middleware Creating Middleware to Protect Login and Sign Up Routes Summary Chapter 13: Create, Read, Update, and Delete Customers Creating the Customer Model Creating the Customer Controller Creating the Customer Views Creating the Customer Routes Creating New Customers Add Create Routes Updating Existing Customers
Page
5
Deleting Customers Summary Chapter 14: Handling Invoices Data Creating the Invoice Model Creating the Invoice Controller Creating the Invoice Views Creating the Invoice Route Create New Invoices Update Invoices Delete Invoices Delete All Invoices When a Customer is Deleted Summary Chapter 15: Using Chart.js On the Dashboard Formatting the Currency Creating the Dashboard Controller Updating the Dashboard View Showing the Revenue Chart Showing Five Latest Invoices Summary Chapter 16: Adding the Search Feature Adding Customer Search Adding Invoice Search Summary Chapter 17: Deploying Node.js Application Preparing the Application for Deployment Pushing Code to GitHub Deploying Node Application to Railway Summary Wrapping Up The Next Step About the author
Page
6
Node.js Web Development For Beginners A Step-By-Step Guide to Build an MVC Web Application With Node.js, Express, and MongoDB By Nathan Sebhastian
Page
7
PREFACE The goal of this book is to provide gentle step-by-step instructions that will help you see how to develop web applications using Node.js, Express, and MongoDB. I’ll teach you why Node.js is a great choice to build a web application. We’ll cover essential web development topics like routing, authentication, input validations, MVC design pattern, and MongoDB query to see how they are implemented in Node.js. After finishing this book, you will know how to build and deploy a web application using Node.js. Working Through This Book This book is broken down into 17 concise chapters, each focusing on a specific aspect of Node.js web development. You’re also going to practice what you’ve learned in each chapter by developing an Invoicing application. I encourage you to write the code you see in this book and run them so that you have a sense of what web development with Node.js looks like. You learn best when you code along with examples in this book. A tip to make the most of this book: Take at least a 10-minute break after finishing a chapter, so that you can regain your energy and focus. Also, don’t despair if some concept is hard to understand. Learning anything new is hard for the first time, especially something technical like programming. The most important thing is to keep going. Requirements To experience the full benefit of this book, basic knowledge of JavaScript is required.
Page
8
If you need some help in learning JavaScript, you can get my book at https://codewithnathan.com/beginning-modern-javascript Source Code In the Summary section of each chapter, you will see a link to download the code added in that chapter from GitHub. You can download the source code as a ZIP archive as shown below: This way, you can continue to the next chapter without getting left behind. Contact If you need help, you can contact me at nathan@codewithnathan.com.
Page
9
You might also want to subscribe to my 7-day free email course called Mindset of the Successful Software Developer at https://g.codewithnathan.com/mindset The email course would help you find the right path forward in your career as a software developer.
Page
10
CHAPTER 1: INTRODUCTION TO NODE.JS Node.js is an open-source runtime environment used for executing JavaScript code outside of the browser. If you’re familiar with JavaScript, you might know that JavaScript was first created to make the web browser programmable. JavaScript exists and runs only inside web browsers. A complete web application is made up of two parts: the frontend or client side, and the backend or server side. The client-server architecture below shows how a web application is developed: The client and server communicate using HTPP requests. When needed, a server might interact with the database to fulfill the request sent by the client. Because JavaScript only runs in the browser, another programming language is required to build a web application. The most popular server-side programming
Page
11
languages are Python, Ruby, and PHP. But all this changed with the invention of Node.js, which is a program that can run JavaScript outside of the browser. By utilizing the power of Node.js, JavaScript can now be used to develop both the client and server side of a web application: Node.js is also an extensible program, so developers have created a collection of open-source libraries and tools that simplify the web development process. What’s more, the architecture of Node.js is very flexible, which allows you to code a prototype application quickly. In short, learning Node.js enables you to build a complete web application using just one language, which is JavaScript. The Exercise Application To make the learning practical, we’re going to build a web application and deploy it to the public. The application we’re going to build is an invoicing application. In this application, users can add customers and invoice information:
Page
12
Users need to register for an account using an email and password:
Page
13
After signing up, they can add new customers to the application:
Page
14
Then, users can create invoices assigned to a customer. The invoice and customer data are connected:
Page
15
In the dashboard page, some information is shown as insights for the user. The application shows the total amount of collected and pending invoices and the number of invoices and customers created. There’s also a graph showing revenue in the last 6 months, as well as the latest invoices:
Page
16
We won’t include features to send the invoice by email or print it. We only focus on building the web application for storing data and showing insights. With this practice, you will get the experience of developing a web application from scratch using Node.js, as well as understanding how to complete a project and organize your code well. Computer Setup To start developing with the Node.js, you need to have three things on your computer: 1. A web browser 2. A code editor 3. The Node.js program Let’s install them in the next section. Installing Chrome Browser Any web browser can be used to browse the Internet, but for development
Page
17
purposes, you need to have a browser with sufficient development tools. The Chrome browser developed by Google is a great browser for web development, and if you don’t have the browser installed, you can download it here: https://www.google.com/chrome/ The browser is available for all major operating systems. Once the download is complete, follow the installation steps presented by the installer to have the browser on your computer. Next, we need to install a code editor. There are several free code editors available on the Internet, such as Sublime Text, Visual Studio Code, and Notepad++. Out of these editors, my favorite is Visual Studio Code because it’s fast and easy to use. Installing Visual Studio Code Visual Studio Code or VSCode for short is a code editor application created for the purpose of writing code. Aside from being free, VSCode is fast and available on all major operating systems. You can download Visual Studio Code here: https://code.visualstudio.com/ When you open the link above, there should be a button showing the version compatible with your operating system as shown below:
Page
18
Figure 1. Install VSCode Click the button to download VSCode, and install it on your computer. Now that you have a code editor installed, the next step is to install Node.js Installing Node.js Node.js is a JavaScript runtime application that enables you to run JavaScript outside of the browser. We need this program to generate and run the web application that we’re going to develop. You can download and install Node.js from https://nodejs.org. Pick the recommended LTS version because it has long-term support. The installation process is pretty straightforward. To check if Node has been properly installed, type the command below on your command line (Command Prompt on Windows or Terminal on Mac): node -v The command line should respond with the version of the Node.js you have on your computer. You now have all the programs needed to start developing a Node.js web application. We’re going to start building the application in the next chapter.
Page
19
Summary In this chapter, we’ve learned what is Node.js and why it’s a great choice, and then we installed the required tools to develop a Node.js application. If you encounter any issues, you can email me at nathan@codewithnathan.com and I will do my best to help you.
Page
20
CHAPTER 2: YOUR FIRST NODE.JS PROJECT Let’s create a server using Node.js and implement the client-server communication that we’ve seen in the previous chapter. First, create a folder on your computer that will be used to store all files and code related to this project. You can name the folder 'finly'. Inside the folder, open your terminal and run the npm command to create a new JavaScript project: npm init npm stands for Node Package Manager. It’s a program used for creating and installing JavaScript libraries and frameworks. It’s included when you install Node.js before. The npm init command is used to initialize a new project and create the package.json file. It will ask several questions about your project, such as the project name, version, and license. For now, just press Enter on all questions until you see the following output: About to write to /finly/package.json: { "name": "finly", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC"
The above is a preview of the first 20 pages. Register to read the complete e-book.
Comments 0
Loading comments...
Reply to Comment
Edit Comment