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: src/content/4/en/part4a.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,22 +54,6 @@ The logger has two functions, __info__ for printing normal log messages, and __e
54
54
55
55
Extracting logging into its own module is a good idea in more ways than one. If we wanted to start writing logs to a file or send them to an external logging service like [graylog](https://www.graylog.org/) or [papertrail](https://papertrailapp.com) we would only have to make changes in one place.
56
56
57
-
The contents of the <i>index.js</i> file used for starting the application gets simplified as follows:
58
-
59
-
```js
60
-
constapp=require('./app') // the actual Express application
61
-
constconfig=require('./utils/config')
62
-
constlogger=require('./utils/logger')
63
-
64
-
app.listen(config.PORT, () => {
65
-
logger.info(`Server running on port ${config.PORT}`)
66
-
})
67
-
```
68
-
69
-
The <i>index.js</i> file only imports the actual application from the <i>app.js</i> file and then starts the application. The function _info_ of the logger-module is used for the console printout telling that the application is running.
70
-
71
-
Now the Express app and the code taking care of the web server are separated from each other following the [best](https://dev.to/nermineslimane/always-separate-app-and-server-files--1nc7)[practices](https://nodejsbestpractices.com/sections/projectstructre/separateexpress). One of the advantages of this method is that the application can now be tested at the level of HTTP API calls without actually making calls via HTTP over the network, this makes the execution of tests faster.
72
-
73
57
The handling of environment variables is extracted into a separate <i>utils/config.js</i> file:
logger.info(`Server running on port ${config.PORT}`)
93
77
```
94
78
79
+
The contents of the <i>index.js</i> file used for starting the application gets simplified as follows:
80
+
81
+
```js
82
+
constapp=require('./app') // the actual Express application
83
+
constconfig=require('./utils/config')
84
+
constlogger=require('./utils/logger')
85
+
86
+
app.listen(config.PORT, () => {
87
+
logger.info(`Server running on port ${config.PORT}`)
88
+
})
89
+
```
90
+
91
+
The <i>index.js</i> file only imports the actual application from the <i>app.js</i> file and then starts the application. The function _info_ of the logger-module is used for the console printout telling that the application is running.
92
+
93
+
Now the Express app and the code taking care of the web server are separated from each other following the [best](https://dev.to/nermineslimane/always-separate-app-and-server-files--1nc7)[practices](https://nodejsbestpractices.com/sections/projectstructre/separateexpress). One of the advantages of this method is that the application can now be tested at the level of HTTP API calls without actually making calls via HTTP over the network, this makes the execution of tests faster.
94
+
95
95
The route handlers have also been moved into a dedicated module. The event handlers of routes are commonly referred to as <i>controllers</i>, and for this reason we have created a new <i>controllers</i> directory. All of the routes related to notes are now in the <i>notes.js</i> module under the <i>controllers</i> directory.
96
96
97
97
The contents of the <i>notes.js</i> module are the following:
0 commit comments