Building a Food Application with Full Stack Javascript
Total Page:16
File Type:pdf, Size:1020Kb
Tuan Vu Building a Food Application with Full Stack JavaScript Metropolia University of Applied Sciences Bachelor of Engineering Information Technology Bachelor’s Thesis 28 April 2020 Abstract Author Tuan Vu Title Building a food application with full stack JavaScript Number of Pages 35 pages Date 28 April 2020 Degree Bachelor of Engineering Degree Programme Information Technology Professional Major Software Engineering Instructors Janne Salonen, Head of the degree program The main goal of the final year project was to develop a full-stack food application based on JavaScript. The idea of using only one programming language on both the client and the server has many advantages. It helps software developers to reuse components and re- sources. The application was built using React in the front-end development and Firebase, Node.js and Express in the back-end development. Node.js is the most popular JavaScript runtime environment at the moment and has no competitors that have as much as 10% of Node.js’s community. Firebase was used as a database for the application and Express was used to build the server. On the front-end, React.js was used along with Redux for state manage- ment. After three months of the first development phase, the application could provide basic fea- tures such as choosing a restaurant and showing directions. The application was tested by a small number of real users and their feedback was positive. Based on the feedback col- lected, the application could move on to the next stage to get more features. The project can be perceived as a success because through this project, the web develop- ment team achieved all the initial objectives, which included developing a working applica- tion for food lovers and trying to meet specific technical and performance goals. Keywords Firebase, Express, React, Node, full stack, JS Contents List of Abbreviations 1 Introduction 1 2 Full stack JavaScript 3 2.1 Introduction to JavaScript 3 2.2 Advantages of full stack JavaScript 4 3 Firebase 6 3.1 Introduction to Firebase 6 3.2 Notable features 6 3.2.1 Firebase authentication 6 3.2.2 Real-time database 7 3.2.3 Cloud storage 8 4 Express 9 4.1 Introduction to Express.js 9 4.2 Middleware 9 4.3 Templating engines 10 5 React 12 5.1 Introduction to React 12 5.2 Outstanding features 13 5.2.1 Components 13 5.2.2 Virtual DOM 15 5.2.3 Lifecycle methods 16 5.2.4 JSX 18 5.3 Redux 18 6 Node.js 20 6.1 Introduction to Node.js 20 6.2 Node.js’s performance 20 6.3 Node architecture 22 6.4 Node package manager (NPM) 23 6.5 Node.JS event loop 23 7 Implementation of the application 25 7.1 User interface 25 7.2 Database 28 7.3 Authentication and authorization 28 7.3.1 User signup 29 7.3.2 User authentication 31 7.4 Server 33 7.5 Directions API 34 8 Conclusion 36 References 37 List of Abbreviations API Application Program Interface CSS Cascading Style Sheets DOM Document Object Model NPM Node Package Manager HTML Hypertext Markup Language JS JavaScript JSX JavaScript XML URL Uniform Resource Locator HTTP Hypertext Transfer Protocol JSON JavaScript Object Notation XML Extensive Markup Language UI User Interface 1 1 Introduction Since the first website was published in 1991, web development technology has grown tremendously and overcome huge obstacles. Current websites have evolved far beyond the first website, which had nothing except a little text and some links (Shontell 2011). This development has required web technology to expand exponentially to make modern websites load faster, be mobile-friendly, and provide easy and simple user experience. In general, web technology is used to improve the appearance and behavior of websites. To meet the criteria set for modern websites, the combination of HTML (Hypertext Markup Language), CSS (Cascading Style Sheets) and JS (JavaScript) which was com- mon in the past is no longer adequate. Web developers now enjoy the emergence of sophisticated and time-nested stacks, such as MERN, to deliver rich user experience. The MERN stack comprises of four main web development technologies: MongoDB for data storage, Express for routing, React for the frontend and Node for the service layer. In the final year project discussed in the thesis, the styling of the website has support from CSS while data management and user authentication utilize the help of Firebase instead of MongoDB. In the limited scope of this thesis, only four main technologies as well as their relevant supporting libraries are discussed and explained thoroughly. The primary goal of this final year project was to develop a food application for a startup. The application aims to help food lovers decide where to eat because the huge number of restaurants and the diverse cuisine they provide may make the decision annoying and time consuming. By providing a more comprehensive user experience and a new mar- keting strategy, the company hopes that this brand-new application can compete with other famous established food applications such as Resq, Wolt or Foodora. This goal required the web development team of Kunam Oy, the company commissioned to de- velop the application, to build a competitive application while keeping its budget at the minimum level due to the fact that startups usually cannot keep the flow of investment money for a long time. Therefore, the choice of the technology used in this project relied heavily on open-source software. 2 The thesis first explains the technology used to build the application, mostly each com- ponent of the MERN stack, except for Firebase replacing MongoDB. Then it provides a closer look into the deployment of the application. 3 2 Full stack JavaScript 2.1 Introduction to JavaScript JS powers almost the entire Internet because it is one of the trendiest programming lan- guages in the world right now. Its popularity is growing more rapidly than that of any programming languages at the moment and multinational conglomerates such as Walmart, Netflix and PayPal build their entire applications around JS. At the beginning, JS was solely utilized inside browsers to create interactive web pages. When it first appeared in 1995, it was referred to as a toy language. Since then JS has grown thanks to its enormous community support and investment by leading technology firms such as Google and Facebook. (Haverbeke 2018.) Nowadays, JS allows building fully developed web or mobile applications as well as video streaming services com- mand-line tools and real-time networking applications such as chats or even games. JS was initially designed to work solely in browsers, so every browser has a JS engine to execute JS code. For example, the JS engines in Firefox and Chrome are SpiderMon- key and v8 respectively. For the front-end web development, it allows having functional- ities such as dragging and dropping, handling events when clicking. (Haverbeke 2018.) Starting from 2009, JS can also run with Node outside of a browser. This invention let JS code be passed to Node for execution to build backend for the web and mobile appli- cations (Haverbeke 2018). JS on the backend can access the database, manipulate data and send that back to the front-end though an API. While ECMAScript is just a specification, JS is a programming language that confirms to this specification. An organization called ECMA is responsible for defining standards and managing ECMAScript specification. The first version ECMAScript was released in 1997. Then starting from 2015, ECMA has been working on annual releases of a newest spec- ification. In 2015, they released ES2015 also known as ES6. This specification defines many new features for JS. (Balter 2019.) 4 2.2 Advantages of full stack JavaScript The first advantage of building the entire application in JS is the fact that using a common language allows the web development team of Kunam Oy to understand the source code better. A common language erases the gap between the front-end and back-end team. Therefore, the development team can be combined into one instead of two, which lowers the cost and reduces the effort of maintaining the team. In addition, using the same lan- guage helps to save time through code reusing and sharing. The same utility such as libraries, templates or models can be used on the server and browser. Decreasing the number of lines of code is a great asset in terms of maintaining and refactoring the source code. (Bush 2016.) Another advantage of utilizing JS is its popularity and wide usage. Looking for an expe- rienced JS developer is relatively easy thanks to its huge number of followers. The 2019 Stack Overflow annual survey indicates JS is the most dominant programming language as 67.8 percent of all the respondents use it, which is equivalent to 23,000 developers on this website alone. Considering the fact that Stack Overflow users account for only 0.4 percent of over 20 million developers in the world, it is estimated that there should be over 10 million JS developers. (Stack Overflow 2019.) 5 Figure 1. Most commonly used programming languages according to Stack Overflow users. Modified from Stack Overflow (2019). Because of its powerful and evolving community, JS can provide an extensive knowledge base and high active community support. Its free and open source development tools are among the largest in the world, which means that JS projects do not need expensive licenses and subscriptions. 6 3 Firebase 3.1 Introduction to Firebase In April 2012, Firebase, Inc., launched the beta version of Firebase called the Firebase Realtime Database.