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 also supports 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:
0 commit comments