...and then my head exploded.
Promises, async/await, ES6 recap, MongoDB, Mongoose, collections, crud, compass, relations, client - server, http request, GET PUT POST, OSI, node.js, express, npm, mocha, test driven development, unit test, integration tests, visual regression test, handlebars, view engine, rest API, nodemon, seeding, fetch, middleware, schema, models ....
Wow - now the boot camp has really started: The first week of module 2 was so packed with new topics and vocabulary that I sometimes didn’t know which end was up.
These three areas were elementary:
1 - Database
Performing CRUD operations on MongoDB and defining models and schemas with mongoose.js
2 - Server-side Javascript
Setting up a server with node.js, understanding the extensions and how they can be managed with npm.
3 . Building dynamic websites
Building routes for get/post requests with express, delivering dynamic websites with the handlebars extension.
In the following paragraphs I will give more details and some examples to hopefully make my gibberish more understandable:
Database
It's some kind of re-education to work in a document-oriented NoSQL database like MongoDB. There are two reasons why getting used to it was a bit of a challenge for me:
- Firstly, during my E-Commerce Master I had a comprehensive introduction to relational databases with SQL
- Secondly, table-based thinking has also been deeply rooted into my mind just because of the tabularly structured data sets you usually handle in Excel or Google spreadsheet.
Therefore MongoDB in its basic form is pure anarchy. The documents are stored in a JSON (JavaScript Object Notation) like structure according to your whim. This gets messy quickly, but you also realize what the advantage is: The DB is fast, lightweight and you can start right away - no major setup necessary.
Order is then created with the Mongoose extension: That provides a straight-forward, schema-based solution to model the application data. It includes built-in type casting, validation, query building, and more, out of the box. What that all means? Well, I’m going to find out.
So for us beginners an essential part of our work this week was: Writing a lot of queries to filter a dataset in the DB, getting used to the tiring syntax ( {{{{{{{}}}}}} ! ) and later - with mongoose - defining what the data for a certain type of object should look like. In other words, define the set of rules ("models" and "schemas") for how data may be stored in the database.
Server side Javascript with node.JS
Ryan Dahl was quite a genius when he decided in 2009 to bring the power of Javascript to the server to build scalable web applications. While the story around him and the node foundation, as well as the company NPM that provides the node package manager (to manage all the extensions for node) is certainly very exciting and worth exploring, we concentrated on the essentials: Setting up a server in a local environment and performing simple operations there which were previously done in the browser.
Dynamic webpage magic with express and handlebars
So far everything has been quite nice but it got really cool when we started to build different routes with express: Basically you teach the server to look out for a certain incoming request (Call of an URL - e.g. "www.example.com/user/id/account") and if the pattern fits to predefined route, the server delivers a corresponding page.
Of course you can define all these pages statically or - better of course - you can render them dynamically on the server side: Based on different factors (e.g. user input, url parameter or data from a database) you build a fitting page from different building blocks (“views” and “partials”).
An example that everyone should be familiar with: In a webshop...
- based on a user input (e.g. search term or setting a filter)
- and a data set (products in the database)
- a page (in this case: search result page) is created by the server (it takes just the products the user wants to see and uses a boilerplate for each product repeatedly - e.g. the product preview - to display them)
- and sends it to the user's browser ("client").
Well, in principle that's all, now I have understood how a web application works in the core. :D
To get hands on experience with that principle we practiced with different labs:
- Ironbeers: Under queries to the PunkAPI, the stock of beer stored there is displayed in the frontend (i.e. a website).
- Spotify Artist Search: Spotify also makes its database available for developers - so we built a simple search where you can search for artists, call up artist albums and load the tracks per album including preview.
Next week we'll find out how the DB is included in this construct and what possibilities still exist with Node and Express - I'm really excited, that's exactly why I'm at Ironhack.