質問するログイン新規登録

質問編集履歴

2

package-lock.jsonについて追記

2019/01/07 02:24

投稿

lightfull
lightfull

スコア11

title CHANGED
File without changes
body CHANGED
@@ -74,4 +74,6 @@
74
74
  app.post('/post-example', function(req, res) {
75
75
  export_func.post_example(req.id, req.name);
76
76
  })
77
- ```
77
+ ```
78
+
79
+ package-lock.jsonは、長すぎてはれませんでした。

1

手順とソースを記載

2019/01/07 02:24

投稿

lightfull
lightfull

スコア11

title CHANGED
File without changes
body CHANGED
@@ -31,4 +31,47 @@
31
31
  ```ここに言語を入力
32
32
  node express-example.js
33
33
  ```
34
- の誤りかと思って、起動しています。
34
+ の誤りかと思って、起動しています。
35
+
36
+ ### 実施した手順(サイトの記載のまま)
37
+ ```ここに言語を入力
38
+ ここではexpress-node-exampleとします。
39
+ $ mkdir express-node-example
40
+ ディレクトリへ移動しましょう。
41
+ $ cd express-node-example
42
+ node.jsを用いるためにnpmをinitします。
43
+ $ npm init
44
+ Expressをインストールします。
45
+ $ npm install express --save
46
+ ```
47
+
48
+
49
+ ### ソース(サイトのコードを丸コピー)
50
+
51
+ express-example.js
52
+ ```
53
+ //expressを使用するのでその設定
54
+ const express = require('express');
55
+ const bodyParser = require('body-parser');
56
+ const app = express();
57
+ //処理を記述した外部ファイルを参照
58
+ var export_func = require("./express-exports");
59
+
60
+ // urlencodedとjsonは別々に初期化
61
+ app.use(bodyParser.urlencoded({
62
+ extended: true
63
+ }));
64
+ app.use(bodyParser.json());
65
+ //listenします。カッコ内の数字を変更することで解放するポート番号を変更できます。
66
+ app.listen(3000);
67
+ //確認のためコンソールに出力します。
68
+ console.log('Server is online.');
69
+ //app.getでGETすることができます。最初の引数を変更することでURLが変更できます。二つ目が実行内容です。
70
+ app.get('/get-example', function(req, res) {
71
+ export_func.get_example();
72
+ })
73
+ //app.getでPOSTすることができます。最初の引数を変更することでURLが変更できます。二つ目が実行内容です。
74
+ app.post('/post-example', function(req, res) {
75
+ export_func.post_example(req.id, req.name);
76
+ })
77
+ ```