Skip to main content

Posts

Showing posts with the label study note

Authentication Project: Secret Page App Part Two (Sign Up Page)

Sign Up Page After a complex set up process, finally we can start to write our routes! Step One: Write register route We will write our register route which will render to a "register" page. In this page, it will have a simple sign up form. Step Two: Create Sign up form We add "register.ejs" in the "views" folder. Then, we create a simple form which the url link will be "/register". Then, we run the app.js and get the "/register", so we can see the form. Step Three: Set up body parser For every form post request, we need to add body parser to make it work. Step Four: Handle user sign up Once users sign up, it will lead them to the secret page. Therefore, we need to write a post route. Inside the post route, we add passport authenticate , which will log the user in and store the correct information and run the serialize method. And we specify to use "local" strategy .  ...

Authentication Project: Secret Page App Part One (Set up & Create User Model)

So far we only write the RESTful routes to send request and redirect to the related page, but we haven't do anything about authentication. If we can sign up, login, and log out, it will make our app more meaningful. Therefore, the course shows us how to create a secret page app, which will allow us to sign up, login to a secret page, and logout. Since it requires so many pieces, I will divided this project into three parts: set up & create user model, sign up, and login/logout. In this post, I am going to show all the set up process. Set Up Step One: Install packages The first thing we are going to do to create a folder "Auth", and inside of "Auth", we need to create another folder "AuthDemo". Then we cd (change directory) to "AuthDemo". Now we can set up the actual application structure by installing a few packages: passport, passport-local, passport-local-mongoose, mongoose, express, ejs, body-parser, and express-session....

Data Association Study Notes: Six Steps to Embedded Data

What is Association? Association will allow us to have multiple pieces of data collections in our database that are related to one another. Just like a Facebook user can have multiple posts or images in his account. Three Types of Association One to One:   One of entity that's related to one another entity. For example, one student has one unique student ID. One to Many:  One entity that's related to many of other entity. For example, one student has multiple social media accounts. And those social media accounts only belong to this student. Many to Many:  Many entity related to both ways. For example, one student can take many course, and one course has many students. Embedded Data In this example, we will do the "One to Many" type. We have user and post. We want one user to have multiple posts. Step One: Set up and define schema Firstly, we need to create a new file "embed,js", and npm install mongoose. Then, we require the mong...

Database Project Study: How To Use Mongoose To Model Your Database?

What is Mongoose? According to Mongoose , Mongoose is an elegant MongoDB object modeling for Node.js. It provides a straight-forward, schema-based solution to model your application data. Basically, Mongoose is a package which helps us interact with Mongo DB. It is a JavaScript layer on top of Mongo DB, and it adds some extra special methods that makes our live easier. How to Install Mongoose? The installation is very simple. We just need to npm install mongoose in our server. Then, we create a JavaScript file, and require the mongoose. Since the Mongoose needs to interact with MongoDB, we need to open another terminal window to call "./mongod"and make sure the MongoDB is running .  Then, we connect Mongoose with MongoDB: mongoose.connect("mongodb://localhost/score_app") . Score Database Project Study In this project, I am going to create a score app which contains student score data. The score data includes three main entries: name...

Database Study Note: Four Basic MongoDB Commands You Should Know

MongoDB is one of the most popular database with Node.js and Express.js. It is a NoSQL database. From Google Image Firstly, we need to install MongoDB in our server. The course TA created a good installation tutorial video on YouTube. Since the MongoDB has updated its system. In the installation, we need to set up the   Ubuntu 16.04 (Xenial)   code instead of 14.04 version which is shown on the video. Once we finish the installation, we need to call "./mongod" and run the code, then open a new terminal window, and call "mongo" , then you are ready to use Mongo shell, which is like JavaScript console.  We can type "help" to learn the main MongoDB commands and their explanation .  After I learned this lecture, I summarized four basic MongoDB commands to do with your database: insert, find, update and remove. Insert I want to create a student databases which include student name and GPA score. I can use insert command to create t...

Database Study Note: What's The Difference Between SQL and NoSQL?

What is Database? According to the course, the database is not only a collection of information data, but it also an interface to interact with data such as add new data, remove data, or edit data. Two Broad Categories of Database: SQL (sequel) SQL is also called relational database. Sequel database are tabular database which data is stored in a table.  From Google Image NoSQL(non-sequel) For NoSQL, they are no tables, and it is basically JavaScript objects with a bunch of key value pairs. What's the difference between SQL and NoSQL? SQL has been around the longest. When we mention database, most people include myself first think of table. Everything is tabular, and if we want to relate data, we have to build other tables to relate that data. However, NoSQL is non-relational database, so we don't have to define any tables and patterns. This is a much more flexible structure. The course also mentioned that flexible structure is bette...

API's Study Notes: How To Make API Request With Node?

The course shows us we can make API's requests with Node. The first thing we need to do is to create the "APIs" directory and touch "request.js" file inside that folder. Then, we need to npm install request package in the APIs directory. Once we have done those basic steps, we can start to require the "request" and make a request from a JavaScript file. In the request, we need to have the "url" , so the server knows where it should request the API. Next, we need to have a function. request("url", function(error, response, body) In the function, there are three things we pass in: error, response, and body . Error: it will hold any potential error that we get such as internet disconnect, 404, and etc. It is important to check for an error. Response : it will be the incoming message that we receive Body : it is the actual response body that came back like HTML code For example, in the "request.js" ...

Study Note For API's: These Two Main Data Formats You Should Know

What is API's? API's stands for application programming interface. They are interfaces for code or computers to talk to one another. For example, we can use a Facebook account to login to Instagram. When we connect these two apps, Instagrams will link to and access your Facebook data. When you upload photos on Instagram, it will be automatically uploaded on Facebook, too. We also use a lot of Web API's every day. Web API's generally to communicate via HTTP. For example, we may ask Yelp API's to recommend 10 nearby Sushi restaurants in a certain zip code. Data Formats There are two main formats that web API is responded with: XML and JSON . When we use the internet, we make an HTTP request and get HTML back. API's don't respond with HTML because HTML contains information about the structure of a page. API's respond with data, not structure. XML XML stands for Extended Markup Language. It is syntactically similar to HTML, but it...

Intermediate Express.js: Six Steps To Develop A Post Request (Study Note)

So far I have learned from the course is all about GET Request which is retrieving information. We run app.get("url", function) in our application. Today, the course shows us how to develop a Post Request by creating a simple friends app. The friends app is a list of friends. There is a form at the bottom, so we can submit a new name to add a new friend to the list. How to develop a post request app? Step One: Set up basic route We create a new directory "PostRequestDemo" under "MoreExpress" directory. Then, in this new directory, we install the express and ejs, and also create a new file "app.js". In the app.js file, we require the express, set up the app, and write a test route "home". We want to make sure everything is connect correctly. Then, we write "/friends" route to render to "friends.ejs" page. In the friend.ejs, we write a simple h1 tag "friend list".  Then, we run the app and see...