-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path18b-buathttpserver.js
executable file
·61 lines (51 loc) · 1.48 KB
/
18b-buathttpserver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// --- Membuat HTTP Server ---
// membuatnya dengan menggunakan Hapi framework
// silahkan pasang package @hapi/hapi denga eksekusi perintah berikut:
// npm install @hapi/hapi
// buka server.js lalu ganti kode nya dg kode pada latihan sebelumnya
/** -- server.js--
*
* const Hapi = require('@hapi/hapi');
*
* const init = async () => {
* const server = Hapi.server({
* port : 5000,
* host : 'localhost',
* });
*
* await server.start();
* console.log(`server berjalan pada ${server.info.uri}`);
* };
*
* init();
*/
// simpan kode tsb, lalu jalankan server dg nodemon pakai perintah:
// npm run start
// buka browser dan jalankan url http://localhost:5000
// sampai disini kita sudah menghubungkan alamat localhost:5000(web server) dg aplikasi client
// silahkan pilih " Change URL"
// lalu isi dengan host beserta port dari web server yang anda buat "localhost:5000"
//nb : ketika anda menggunakan ESlint, terkadang ditampilkan error
// apabila code style yg anda pilih adalah AirBnB , penggunaan console dianggap warning
// maka dari itu bs dimatikan dg aturan no-console pada berkas .eslintrc.json dg menambahkan properti no-console bernilai off
/** --eslintrc.json --
*
* {
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": [
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"no-console": "off"
}
}
*
*/
// dengan begitu, warning penggunaan console akan hilang