Skip to content

Commit d7dc92c

Browse files
committed
part 3 tweaks
1 parent 2ccfc64 commit d7dc92c

File tree

29 files changed

+179
-135
lines changed

29 files changed

+179
-135
lines changed

src/content/13/en/part13a.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ We can use the _heroku config_ command to get the <i>connect string</i>, which i
112112
```bash
113113
heroku config -a <app-name>
114114
=== cryptic-everglades-76708 Config Vars
115-
DATABASE_URL: postgres://<username>:<password>@<host-of-postgres-addon>:5432/<db-name>
115+
DATABASE_URL: postgres://<username>:thepasswordishere@<host-of-postgres-addon>:5432/<db-name>
116116
```
117117

118118
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
317317

318318
```bash
319319
$ cat .env
320-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
320+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
321321
```
322322

323323
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
339339

340340
```bash
341341
$ cat .env
342-
DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/postgres
342+
DATABASE_URL=postgres://postgres:thepasswordishere@127.0.0.1:5432/postgres
343343
```
344344

345345
Password was shown when the database was created, so hopefully you have not lost it!

src/content/13/es/part13a.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ heroku create
8181
heroku addons:create heroku-postgresql:hobby-dev -a <app-name>
8282
heroku config -a <app-name>
8383
=== cryptic-everglades-76708 Config Vars
84-
DATABASE_URL: postgres://<username>:<password>@<host-of-postgres-addon>:5432/<db-name>
84+
DATABASE_URL: postgres://<username>:thepasswordishere@<host-of-postgres-addon>:5432/<db-name>
8585
```
8686

8787
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
236236
237237
```bash
238238
$ cat .env
239-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
239+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
240240
```
241241
242242
Probemos una conexión exitosa:

src/content/13/fi/osa13a.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ heroku create
108108
heroku addons:create heroku-postgresql:hobby-dev
109109
heroku config
110110
=== cryptic-everglades-76708 Config Vars
111-
DATABASE_URL: postgres://<username>:<password>@ec2-44-199-83-229.compute-1.amazonaws.com:5432/<db-name>
111+
DATABASE_URL: postgres://<username>:thepasswordishere@ec2-44-199-83-229.compute-1.amazonaws.com:5432/<db-name>
112112
```
113113

114114
Tietokantaan saadaan psql-konsoliyhteys suorittamalla _psql_ Herokun palvelimella seuraavasti (huomaa, että komennon parametrit riippuvat Heroku-sovelluksen connect urlista):
@@ -308,7 +308,7 @@ Herokua käyttäessäsi saat connect stringin selville komennolla _heroku config
308308
309309
```bash
310310
$ cat .env
311-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
311+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
312312
```
313313
314314
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:
329329
330330
```bash
331331
$ cat .env
332-
DATABASE_URL=postgres://postgres:<password>@localhost:5432/postgres
332+
DATABASE_URL=postgres://postgres:thepasswordishere@localhost:5432/postgres
333333
```
334334
335335
Salasana on se, jonka on otettu talteen tietokantaa luodessa.

src/content/13/zh/part13a.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ heroku create
9797
heroku addons:create heroku-postgresql:hobby-dev -a <app-name>
9898
heroku config -a <app-name>
9999
=== cryptic-everglades-76708 Config Vars
100-
DATABASE_URL: postgres://<username>:<password>@<host-of-postgres-addon>:5432/<db-name>
100+
DATABASE_URL: postgres://<username>:thepasswordishere@<host-of-postgres-addon>:5432/<db-name>
101101
```
102102

103103
<!-- 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
262262

263263
```bash
264264
$ cat .env
265-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
265+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
266266
```
267267

268268
Let's test for a successful connection:

src/content/3/en/part3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ lang: en
88

99
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.
1010

11-
<i>Part updated 14th August 2023</i>
12-
- <i>Create React App replaced with Vite</i>
11+
<i>Part updated 9th February 2024</i>
12+
- <i>No major changes</i>
1313

1414
</div>

src/content/3/en/part3a.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ echo "Error: no test specified" && exit 1
9393

9494
### Simple web server
9595

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:
9797

9898
```js
9999
const http = require('http')
@@ -120,7 +120,7 @@ We can open our humble application in the browser by visiting the address <http:
120120

121121
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.
122122

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:
124124

125125
```bash
126126
➜ hello npm start
@@ -138,7 +138,7 @@ Error: listen EADDRINUSE :::3001
138138
at listenInCluster (net.js:1378:12)
139139
```
140140

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.
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.
142142

143143
Let's take a closer look at the first line of the code:
144144

@@ -154,7 +154,7 @@ import http from 'http'
154154

155155
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).
156156

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.
158158

159159
CommonJS modules function almost exactly like ES6 modules, at least as far as our needs in this course are concerned.
160160

@@ -251,7 +251,7 @@ The source code for the dependency is installed in the <i>node\_modules</i> dire
251251

252252
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.
253253

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?
255255

256256
```json
257257
"express": "^4.18.2"
@@ -273,7 +273,7 @@ Likewise, if we start working on the project on another computer, we can install
273273
npm install
274274
```
275275

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.
277277

278278
### Web and express
279279

@@ -379,7 +379,7 @@ The contents of <i>package.json</i> have also changed:
379379
"express": "^4.18.2"
380380
},
381381
"devDependencies": {
382-
"nodemon": "^2.0.20"
382+
"nodemon": "^3.0.3"
383383
}
384384
}
385385
```
@@ -603,8 +603,8 @@ Many tools exist for making the testing of backends easier. One of these is a co
603603
Let's install the Postman desktop client [from here](https://www.postman.com/downloads/) and try it out:
604604

605605
![postman screenshot on api/notes/2](../../images/3/11x.png)
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
608608

609609
Using Postman is quite easy in this situation. It's enough to define the URL and then select the correct request type (DELETE).
610610

@@ -672,9 +672,9 @@ The application prints the data that we sent in the request to the console:
672672

673673
**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:
674674

675-
![nodemon error as typing requre not defined](../../images/3/16.png)
675+
![nodemon error as typing requre not defined](../../images/3/16e.png)
676676

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.
678678

679679
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:
680680

src/content/3/en/part3b.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const cors = require('cors')
7373
app.use(cors())
7474
```
7575

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.
7777

7878
You can read more about CORS from [Mozilla's page](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).
7979

@@ -85,19 +85,19 @@ The react app running in the browser now fetches the data from node/express-serv
8585

8686
### Application to the Internet
8787

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.
8989

9090
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.
9191

9292
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.
9393

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.
9595

9696
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.
9797

9898
Render might be a bit easier to use since it does not require any software to be installed on your machine.
9999

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.
101101

102102
Some course participants have also used the following services:
103103

@@ -163,7 +163,7 @@ Fly.io creates a file <i>fly.toml</i> in the root of your app where we can confi
163163
processes = ["app"]
164164
```
165165

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.
167167

168168
We are now ready to deploy the app to the Fly.io servers. That is done with the following command:
169169

@@ -174,12 +174,12 @@ fly deploy
174174
If all goes well, the app should now be up and running. You can open it in the browser with the command
175175

176176
```bash
177-
fly open
177+
fly apps open
178178
```
179179

180180
A particularly important command is _fly logs_. This command can be used to view server logs. It is best to keep logs always visible!
181181

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.
183183

184184
**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
185185

@@ -252,7 +252,7 @@ app.listen(PORT, () => {
252252

253253
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.
254254

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.
256256

257257
A production build for applications created with Vite can be created with the command [npm run build](https://vitejs.dev/guide/build.html).
258258

@@ -363,11 +363,11 @@ fly deploy
363363
364364
The application works perfectly, except we haven't added the functionality for changing the importance of a note to the backend yet.
365365
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.
367367
368368
![screenshot of notes application](../../images/3/30new.png)
369369
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>
371371
372372
Our application saves the notes to a variable. If the application crashes or is restarted, all of the data will disappear.
373373

0 commit comments

Comments
 (0)