You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The database can be accessed by running _psql_ command on the Heroku server as follows (note that the command parameters depend on the connection url of the Heroku database):
@@ -317,7 +317,7 @@ If Heroku is used, the connect string can be seen by using the command _heroku c
When using Fly.io, the local connection to the database should first be enabled by [tunneling](https://fly.io/docs/reference/postgres/#connecting-to-postgres-from-outside-fly)
@@ -339,7 +339,7 @@ The Fly.io connect-string is of the form
Particularmente cuando se utiliza una base de datos relacional, también es esencial acceder a la base de datos directamente. Hay muchas maneras de hacer esto, hay varias interfaces gráficas de usuario diferentes, como [pgAdmin](https://www.pgadmin.org/). Sin embargo, utilizaremos la herramienta de línea de comandos de Postgres [psql](https://www.postgresql.org/docs/current/app-psql.html).
@@ -236,7 +236,7 @@ La <i>cadena de conexión</i> de la base de datos, que es revelada por el comand
Fly.io:a käyttäessä paikallinen tietokantayhteys taytyy ensin tehdä mahdolliseksi [tunneloimalla](https://fly.io/docs/reference/postgres/#connecting-to-postgres-from-outside-fly) paikallisen koneen portti 5432 Fly.io:n tietokannan porttiin komennolla
@@ -329,7 +329,7 @@ Fly.io:n connect-string on seuraavaa muotoa:
<!-- Particularly when using a relational database, it is essential to access the database directly as well. There are many ways to do this, there are several different graphical user interfaces, such as [pgAdmin](https://www.pgadmin.org/). However, we will be using Postgres [psql](https://www.postgresql.org/docs/current/app-psql.html) command-line tool.-->
@@ -262,7 +262,7 @@ The database <i>connect string</i>, which is revealed by the _heroku config_ com
Copy file name to clipboardExpand all lines: src/content/3/en/part3.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ lang: en
8
8
9
9
In this part our focus shifts towards the backend, that is, towards implementing functionality on the server side of the stack. We will implement a simple REST API in Node.js by using the Express library, and the application's data will be stored in a MongoDB database. At the end of this part, we will deploy our application to the internet.
Copy file name to clipboardExpand all lines: src/content/3/en/part3a.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ echo "Error: no test specified" && exit 1
93
93
94
94
### Simple web server
95
95
96
-
Let's change the application into a web server by editing the _index.js_ file as follow:
96
+
Let's change the application into a web server by editing the _index.js_ file as follows:
97
97
98
98
```js
99
99
consthttp=require('http')
@@ -120,7 +120,7 @@ We can open our humble application in the browser by visiting the address <http:
120
120
121
121
The server works the same way regardless of the latter part of the URL. Also the address <http://localhost:3001/foo/bar> will display the same content.
122
122
123
-
**NB**if port 3001 is already in use by some other application, then starting the server will result in the following error message:
123
+
**NB**If port 3001 is already in use by some other application, then starting the server will result in the following error message:
You have two options. Either shut down the application using port 3001 (the json-server in the last part of the material was using port 3001), or use a different port for this application.
141
+
You have two options. Either shut down the application using port 3001 (the JSON Server in the last part of the material was using port 3001), or use a different port for this application.
142
142
143
143
Let's take a closer look at the first line of the code:
144
144
@@ -154,7 +154,7 @@ import http from 'http'
154
154
155
155
These days, code that runs in the browser uses ES6 modules. Modules are defined with an [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) and taken into use with an [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import).
156
156
157
-
However, Node.js uses so-called [CommonJS](https://en.wikipedia.org/wiki/CommonJS) modules. The reason for this is that the Node ecosystem needed modules long before JavaScript supported them in the language specification. Node supports now also the use of ES6 modules, but since the support is not quite perfect yet, we'll stick to CommonJS modules.
157
+
Node.js uses by default so-called [CommonJS](https://en.wikipedia.org/wiki/CommonJS) modules. The reason for this is that the Node ecosystem needed modules long before JavaScript supported them in the language specification. Currently, Node supports also the use of ES6 modules, but since the support is not quite perfect yet, we'll stick to CommonJS modules.
158
158
159
159
CommonJS modules function almost exactly like ES6 modules, at least as far as our needs in this course are concerned.
160
160
@@ -251,7 +251,7 @@ The source code for the dependency is installed in the <i>node\_modules</i> dire
251
251
252
252
These are the dependencies of the express library and the dependencies of all of its dependencies, and so forth. These are called the [transitive dependencies](https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/) of our project.
253
253
254
-
The version 4.18.2 of express was installed in our project. What does the caret in front of the version number in <i>package.json</i> mean?
254
+
Version 4.18.2 of Express was installed in our project. What does the caret in front of the version number in <i>package.json</i> mean?
255
255
256
256
```json
257
257
"express": "^4.18.2"
@@ -273,7 +273,7 @@ Likewise, if we start working on the project on another computer, we can install
273
273
npm install
274
274
```
275
275
276
-
If the <i>major</i> number of a dependency does not change, then the newer versions should be [backwards compatible](https://en.wikipedia.org/wiki/Backward_compatibility). This means that if our application happened to use version 4.99.175 of express in the future, then all the code implemented in this part would still have to work without making changes to the code. In contrast, the future 5.0.0 version of express[may contain](https://expressjs.com/en/guide/migrating-5.html) changes that would cause our application to no longer work.
276
+
If the <i>major</i> number of a dependency does not change, then the newer versions should be [backwards compatible](https://en.wikipedia.org/wiki/Backward_compatibility). This means that if our application happened to use version 4.99.175 of Express in the future, then all the code implemented in this part would still have to work without making changes to the code. In contrast, the future 5.0.0 version of Express[may contain](https://expressjs.com/en/guide/migrating-5.html) changes that would cause our application to no longer work.
277
277
278
278
### Web and express
279
279
@@ -379,7 +379,7 @@ The contents of <i>package.json</i> have also changed:
379
379
"express": "^4.18.2"
380
380
},
381
381
"devDependencies": {
382
-
"nodemon": "^2.0.20"
382
+
"nodemon": "^3.0.3"
383
383
}
384
384
}
385
385
```
@@ -603,8 +603,8 @@ Many tools exist for making the testing of backends easier. One of these is a co
603
603
Let's install the Postman desktop client [from here](https://www.postman.com/downloads/) and try it out:
604
604
605
605

606
-
NB: Postman is also available on VS Code which can be dowloaded from the Extension tab on the left -> search for Postman -> First result (Verified Publisher) -> Install
607
-
You will then see an extra icon added on the activity bar below the extensions tab. Once you login, you can follow from the steps below
606
+
NB: Postman is also available on VS Code which can be downloaded from the Extension tab on the left -> search for Postman -> First result (Verified Publisher) -> Install
607
+
You will then see an extra icon added on the activity bar below the extensions tab. Once you log in, you can follow the steps below
608
608
609
609
Using Postman is quite easy in this situation. It's enough to define the URL and then select the correct request type (DELETE).
610
610
@@ -672,9 +672,9 @@ The application prints the data that we sent in the request to the console:
672
672
673
673
**NB** <i>Keep the terminal running the application visible at all times</i> when you are working on the backend. Thanks to Nodemon any changes we make to the code will restart the application. If you pay attention to the console, you will immediately be able to pick up on errors that occur in the application:
674
674
675
-

675
+

676
676
677
-
Similarly, it is useful to check the console for making sure that the backend behaves as we expect it to in different situations, like when we send data with an HTTP POST request. Naturally, it's a good idea to add lots of <em>console.log</em> commands to the code while the application is still being developed.
677
+
Similarly, it is useful to check the console to make sure that the backend behaves as we expect it to in different situations, like when we send data with an HTTP POST request. Naturally, it's a good idea to add lots of <em>console.log</em> commands to the code while the application is still being developed.
678
678
679
679
A potential cause for issues is an incorrectly set <i>Content-Type</i> header in requests. This can happen with Postman if the type of body is not defined correctly:
Copy file name to clipboardExpand all lines: src/content/3/en/part3b.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@ const cors = require('cors')
73
73
app.use(cors())
74
74
```
75
75
76
-
And the frontend works! However, the functionality for changing the importance of notes has not yet been implemented on the backend.
76
+
Now most of the features in the frontend work! The functionality for changing the importance of notes has not yet been implemented on the backend so naturally that does not yet work in the frontend. We shall fix that later.
77
77
78
78
You can read more about CORS from [Mozilla's page](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).
79
79
@@ -85,19 +85,19 @@ The react app running in the browser now fetches the data from node/express-serv
85
85
86
86
### Application to the Internet
87
87
88
-
Now that the whole stack is ready, let's move our application to the internet.
88
+
Now that the whole stack is ready, let's move our application to Internet.
89
89
90
90
There is an ever-growing number of services that can be used to host an app on the internet. The developer-friendly services like PaaS (i.e. Platform as a Service) take care of installing the execution environment (eg. Node.js) and could also provide various services such as databases.
91
91
92
92
For a decade, [Heroku](http://heroku.com) was dominating the PaaS scene. Unfortunately the free tier Heroku ended at 27th November 2022. This is very unfortunate for many developers, especially students. Heroku is still very much a viable option if you are willing to spend some money. They also have [a student program](https://www.heroku.com/students) that provides some free credits.
93
93
94
-
We are now introducing two services [Fly.io](https://fly.io/) and [Render](https://render.com/) that both have a (limited) free plan. Fly.io is our "official" hosting service since it can be for sure used also on the parts 11 and 13 of the course. Render will be fine at least for the other parts of this course.
94
+
We are now introducing two services [Fly.io](https://fly.io/) and [Render](https://render.com/) that both have a (limited) free plan. Fly.io is our "official" hosting service since it can be for sure used also on parts 11 and 13 of the course. Render will be fine at least for the other parts of this course.
95
95
96
96
Note that despite using the free tier only, Fly.io <i>might</i> require one to enter their credit card details. At the moment Render can be used without a credit card.
97
97
98
98
Render might be a bit easier to use since it does not require any software to be installed on your machine.
99
99
100
-
There are also some other free hosting options that work well for this course, at least for all parts other than part 11 (CI/CD) that might have one tricky exercise for other platforms.
100
+
There are also some other free hosting options that work well for this course, at least for all parts other than part 11 (CI/CD) which might have one tricky exercise for other platforms.
101
101
102
102
Some course participants have also used the following services:
103
103
@@ -163,7 +163,7 @@ Fly.io creates a file <i>fly.toml</i> in the root of your app where we can confi
163
163
processes = ["app"]
164
164
```
165
165
166
-
We have now defined in the part [env] that environment variable PORT will get the correct port (defined in part [http_service]) where the app should create the server. Note that the definition might be already there, but some times it has been missing.
166
+
We have now defined in the part [env] that environment variable PORT will get the correct port (defined in part [http_service]) where the app should create the server.
167
167
168
168
We are now ready to deploy the app to the Fly.io servers. That is done with the following command:
169
169
@@ -174,12 +174,12 @@ fly deploy
174
174
If all goes well, the app should now be up and running. You can open it in the browser with the command
175
175
176
176
```bash
177
-
fly open
177
+
fly apps open
178
178
```
179
179
180
180
A particularly important command is _fly logs_. This command can be used to view server logs. It is best to keep logs always visible!
181
181
182
-
**Note:**If you are using Fly.io, Fly may create 2 machines for your app, if it does then the state of the data in your app will be inconsistent between requests, i.e. you would have two machines each with its own notes variable, you could POST to one machine then your next GET could go to another machine. You can check the number of machines by using the command "$ fly scale show", if the COUNT is greater than 1 then you can enforce it to be 1 with the command "$ fly scale count 1". The machine count can also be checked on the dashboard.
182
+
**Note:** Fly may create 2 machines for your app, if it does then the state of the data in your app will be inconsistent between requests, i.e. you would have two machines each with its own notes variable, you could POST to one machine then your next GET could go to another machine. You can check the number of machines by using the command "$ fly scale show", if the COUNT is greater than 1 then you can enforce it to be 1 with the command "$ fly scale count 1". The machine count can also be checked on the dashboard.
183
183
184
184
**Note:** In some cases (the cause is so far unknown) running Fly.io commands especially on Windows WSL (Windows Subsystem for Linux) has caused problems. If the following command just hangs
185
185
@@ -252,7 +252,7 @@ app.listen(PORT, () => {
252
252
253
253
So far we have been running React code in <i>development mode</i>. In development mode the application is configured to give clear error messages, immediately render code changes to the browser, and so on.
254
254
255
-
When the application is deployed, we must create a [production build](https://vitejs.dev/guide/build.html) or a version of the application which is optimized for production.
255
+
When the application is deployed, we must create a [production build](https://vitejs.dev/guide/build.html) or a version of the application that is optimized for production.
256
256
257
257
A production build for applications created with Vite can be created with the command [npm run build](https://vitejs.dev/guide/build.html).
258
258
@@ -363,11 +363,11 @@ fly deploy
363
363
364
364
The application works perfectly, except we haven't added the functionality for changing the importance of a note to the backend yet.
365
365
366
-
<i>**NOTE:** If you are using Fly.io, there could be a .dockerignore file that specifies the exclusion of the "./build" directory during deployment. To ensure it gets deployed, consider renaming the ./build directory to ./static_build or an equivalent name.</i>
366
+
<strong>NOTE:</strong> When using Fly.io, be aware that the _.dockerignore_ file in your project directory lists files not uploaded during deployment. The dist directory is included by default. To deploy this directory, remove its reference from the .dockerignore file, ensuring your app is get properly deployed.
367
367
368
368

369
369
370
-
<i>**NOTE:** changing of the importance DOES NOT work yet since the backend has no implementation for it yet.</i>
370
+
<i>**NOTE:** changing the importance DOES NOT work yet since the backend has no implementation for it yet.</i>
371
371
372
372
Our application saves the notes to a variable. If the application crashes or is restarted, all of the data will disappear.
0 commit comments