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
Copy file name to clipboardExpand all lines: 0x05-Node_JS_basic/full_server/README.md
+16-13
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,20 @@
4
4
* Create `2` directories within:
5
5
* `controllers`
6
6
* `routes`
7
-
* Create a file `full_server/utils.js`, in the file create a function named `readDatabase` that accepts a file path as argument:
7
+
* Create a file [full_server/utils.js](./utils.js), in the file create a function named `readDatabase` that accepts a file path as argument:
8
8
* It should read the database asynchronously
9
9
* It should return a promise
10
10
* When the file is not accessible, it should reject the promise with the error
11
11
* When the file can be read, it should return an object of arrays of the firstname of students per fields
12
12
13
13
### 8.2 Write the App controller
14
-
Inside the file `full_server/controllers/AppController.js`:
14
+
Inside the file [full_server/controllers/AppController.js](./controllers/AppController.js):
15
15
16
16
* Create a class named `AppController`. Add a static method named `getHomepage`
17
17
* The method accepts `request` and `response` as argument. It returns a `200` status and the message `Hello Holberton School!`
18
18
19
19
### 8.3 Write the Students controller
20
-
Inside the file `full_server/controllers/StudentsController.js`, create a class named `StudentsController`. Add two static methods:
20
+
Inside the file [full_server/controllers/StudentsController.js](./controllers/StudentsController.js), create a class named `StudentsController`. Add two static methods:
21
21
22
22
The first one is `getAllStudents`:
23
23
@@ -28,33 +28,36 @@ The first one is `getAllStudents`:
28
28
* And for each field (*order by alphabetic order case insensitive*), a line that displays the number of students in the field, and the list of first names (*ordered by appearance in the database file*) with the following format: `Number of students in FIELD: 6. List: LIST_OF_FIRSTNAMES`
29
29
* If the database is not available, it should return a status `500` and the error message `Cannot load the database`
30
30
31
-
The second one is getAllStudentsByMajor:
31
+
The second one is `getAllStudentsByMajor`:
32
32
33
-
* The method accepts request and response as argument
34
-
* It should return a status 200
35
-
* It uses a parameter that the user can pass to the browser major. The major can only be CS or SWE. If the user is passing another parameter, the server should return a 500 and the error Major parameter must be CS or SWE
36
-
* It calls the function readDatabase from the utils file, and display in the page the list of first names for the students (ordered by appearance in the database file) in the specified field List: LIST_OF_FIRSTNAMES_IN_THE_FIELD
37
-
* If the database is not available, it should return a status 500 and the error message Cannot load the database
33
+
* The method accepts `request` and `response` as argument
34
+
* It should return a status `200`
35
+
* It uses a parameter that the user can pass to the browser `major`.
36
+
The `major` can only be `CS` or `SWE`.
37
+
If the user is passing another parameter,
38
+
the server should return a `500` and the error `Major parameter must be CS or SWE`
39
+
* It calls the function `readDatabase` from the `utils` file, and display in the page the list of first names for the students (*ordered by appearance in the database file*) in the specified field `List: LIST_OF_FIRSTNAMES_IN_THE_FIELD`
40
+
* If the database is not available, it should return a status `500` and the error message `Cannot load the database`
38
41
39
42
### 8.4 Write the routes
40
-
Inside the file `full_server/routes/index.js`:
43
+
Inside the file [full_server/routes/index.js](./routes/index.js):
41
44
42
45
* Link the route `/` to the `AppController`
43
46
* Link the route `/students` and `/students/:major` to the `StudentsController`
44
47
45
48
### 8.5 Write the server reusing everything you created
46
-
Inside the file named `full_server/server.js`, create a small `Express` server:
49
+
Inside the file named [full_server/server.js](./server.js), create a small `Express` server:
47
50
48
51
* It should use the routes defined in `full_server/routes/index.js`
49
-
*It should use the port `1245`
52
+
* It should use the port `1245`
50
53
51
54
### 8.6 Update `package.json` (if you are running it from outside the folder full_server)
52
55
If you are starting node from outside of the folder `full_server`, you will have to update the command `dev` by: `nodemon --exec babel-node --presets babel-preset-env ./full_server/server.js ./database.csv`
53
56
54
57
#### Warning:
55
58
56
59
* Don’t forget to export your express app at the end of `server.js` (`export default app;`)
57
-
* The database filename is passed as argument of the `server.js` BUT, for testing purpose, you should retrieve this filename at the execution (when `getAllStudents` or g`etAllStudentsByMajor` are called for example)
60
+
* The database filename is passed as argument of the `server.js`**BUT**, for testing purpose, you should retrieve this filename at the execution (when `getAllStudents` or g`etAllStudentsByMajor` are called for example)
0 commit comments