-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Écrivez un serveur qui lit un fichier, le parse en tant que JSON et envoie | ||
le contenu analysé à l’utilisateur. | ||
|
||
Le numéro de port sera passé en `process.argv[2]`. Le nom du fichier à lire | ||
sera passé en `process.argv[3]`. | ||
|
||
Répondez à l’aide de : | ||
|
||
```js | ||
res.json(object) | ||
``` | ||
|
||
L’ensemble du traitement doit correspondre au chemin de ressource '/books'. | ||
|
||
|
||
----------------------------- | ||
|
||
## CONSEILS | ||
|
||
Pour lire un fichier, on a le module noyau `fs`, par exemple : | ||
|
||
```js | ||
fs.readFile(filename, callback) | ||
``` | ||
|
||
Tandis que pour analyser un contenu JSON, on utilise `JSON.parse` : | ||
|
||
```js | ||
object = JSON.parse(string) | ||
``` |