@@ -28,40 +28,30 @@ router.get("/", function (req, res) {
28
28
headers : {
29
29
"User-Agent" : rua ,
30
30
} ,
31
- } )
32
- . then ( function ( response ) {
33
- $ = cheerio . load ( response . data ) ;
31
+ } ) . then ( function ( response ) {
32
+ $ = cheerio . load ( response . data ) ;
34
33
35
- if ( dutchRandomWord . length > 0 ) {
36
- dutchRandomWord = [ ] ;
37
- }
38
- let post = $ ( "#output > div" ) ;
39
- let word = post . find ( `div:nth-child(${ rand } ) > h3` ) [ 0 ] . children [ 0 ] . data ;
40
- let definition = post
41
- . find ( `div:nth-child(${ rand } ) > span` ) [ 0 ]
42
- . children [ 0 ] . data . replace ( "Meaning: " , "" ) ;
43
- let pronunciation = pronounce ( word ) ;
44
- dutchRandomWord . push ( {
45
- word : decodeURI ( word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ) ,
46
- definition : decodeURI (
47
- definition . charAt ( 0 ) . toUpperCase ( ) + definition . slice ( 1 )
48
- ) ,
49
- pronunciation : decodeURI (
50
- pronunciation . charAt ( 0 ) . toUpperCase ( ) + pronunciation . slice ( 1 )
51
- ) ,
52
- } ) ;
53
- console . log ( dutchRandomWord ) ;
54
- res . send ( JSON . stringify ( dutchRandomWord , null , 2 ) ) ;
55
- } )
56
- . catch ( function ( error ) {
57
- if ( ! error . response ) {
58
- console . log ( "API URL is Missing" ) ;
59
- res . json ( "API URL is Missing" ) ;
60
- } else {
61
- console . log ( "Something Went Wrong - Enter the Correct API URL" ) ;
62
- res . json ( "Something Went Wrong - Enter the Correct API URL" ) ;
63
- }
34
+ if ( dutchRandomWord . length > 0 ) {
35
+ dutchRandomWord = [ ] ;
36
+ }
37
+ let post = $ ( "#output > div" ) ;
38
+ let word = post . find ( `div:nth-child(${ rand } ) > h3` ) [ 0 ] . children [ 0 ] . data ;
39
+ let definition = post
40
+ . find ( `div:nth-child(${ rand } ) > span` ) [ 0 ]
41
+ . children [ 0 ] . data . replace ( "Meaning: " , "" ) ;
42
+ let pronunciation = pronounce ( word ) ;
43
+ dutchRandomWord . push ( {
44
+ word : decodeURI ( word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ) ,
45
+ definition : decodeURI (
46
+ definition . charAt ( 0 ) . toUpperCase ( ) + definition . slice ( 1 )
47
+ ) ,
48
+ pronunciation : decodeURI (
49
+ pronunciation . charAt ( 0 ) . toUpperCase ( ) + pronunciation . slice ( 1 )
50
+ ) ,
64
51
} ) ;
52
+ console . log ( dutchRandomWord ) ;
53
+ res . send ( JSON . stringify ( dutchRandomWord , null , 2 ) ) ;
54
+ } ) ;
65
55
} ) ;
66
56
67
57
module . exports = router ;
0 commit comments