Learning Node.js & Express (2)
Tags: node, express, mongodb, backend
Published: 2019-11-18 20:40:27

---
title: Learning Node.js & Express (2)
published: true
description: Excerpts from my Node.js and Express Learning Phase
tags: #Nodejs #Express #MongoDB #backend
series: Journey to MEAN Stack
---

Hello once again!

Yesterday, I [wrote](https://dev.to/benneee_/learning-node-js-express-1-3ckj) briefly about how I have started learning Node.js and Express. I mentioned I would be sticking with the tutorial on [Mozilla Development Network for Node.js and Express](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction). I also talked about other supporting materials such as [Beginning Node.js](https://www.amazon.com/Beginning-Node-js-Basarat-Syed/dp/1484201884/ref=sr_1_1?keywords=BEGINNING+NODEJS&qid=1574029505&s=digital-text&sr=8-1) and [Learn NodeJS in One Day](https://www.amazon.com/Learn-NodeJS-Day-Complete-Examples-ebook/dp/B01N7A4NFT).

Today, I want to run through my progress so far and share a few things I have come to understand so far. The first thing I created after going through the theoretical parts of Node.js from the 'Learn Node.js in One Day' book was this [simple server](https://github.com/Benneee/Learning-Node-JS/blob/master/index.js), all it did was print "Hello World" on the screen when you navigate to port 8000 while the code is running in the terminal. This made me smile.

I dove deeper into the MDN tutorials in the next few days, then I got introduced to the minimalist and unopinionated Node.js web framework called Express. One of the things I like about Express is the Express Generator, simply because of the ease to generate a project by using _express name-of-app/project_. On running this command, the following will be generated: 

![Snapshot of files & directories generated](https://raw.githubusercontent.com/Benneee/Learning-Node-JS/master/Screenshot%20from%202019-11-18%2021-30-02.png)

I will talk about these files in a later article.

**View Engines**
The MDN tutorial's first project endeavour is to build a local library website, now, you would expect a website to have actual pages we can see stuff like 'books', right? Node.js does provide us with view options made possible by something called 'Template Engines'. These [Template Engines](https://github.com/expressjs/express/wiki#template-engines) help us to present data on the client-side. Ordinarily, the default template engine provided if you run _express hello-world_ would be the engine called [Pug (formerly Jade)](https://pugjs.org/api/getting-started.html).

MDN does a good job of explaining consideration points before selecting a template, some of them include: 
* Time to productivity
* Popularity and activity

See the write-up [here](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/skeleton_website#What_view_engine_should_I_use)


**Database**
When building APIs, you will most likely want to save data somewhere, persist whatever is created or edited on the client, this is where the database comes in. Node.js works with various types of database, SQL or NoSQL and Express works with the databases Node.js supports as it does not have any specifics when it comes to Databases. 
MDN describes how you can communicate with your preferred database in two ways.
* Using the database's native query language
* Using an Object Data Model or Object Relational Model

A good example of the second option is Mongoose, the ORM/ODM used to communicate with a MongoDB database. Choosing an ORM like Mongoose is advantageous because we can avoid the use of database semantics and continue thinking in terms of JavaScript objects. These [points from MDN](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose#What_ORMODM_should_I_use) can help you make a decision when selecting an ORM or ODM.

**Conclusion**
In this article, I talked about the Express Generator, View engines and Database. In the next set of articles, I will talk about the Local Library project and my progress in it so far. As always, the code for this journey [lives here](https://github.com/Benneee/Learning-Node-JS)

Thank you for sticking with me to this point. 
Happy Building!