3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.jsを使っての写真共有ソフト作成

Posted at

目的

 ある時男は思った。写真をみんなに見せたい。
 そして男は思った。アプリを使って共有しようと調べた結果
 googleフォト⇒ googleアカウント必須(いちいち知り合いのアカウント聞いて権限つけたはめんどい)
 amazonフォト⇒ アマゾンアカウント必須
 30days Album⇒150枚限定
 インスタ⇒やっぱアカウント問題が・・・

 んー色々制限がめんどい。見せたい人にご年配の人もいるのでできるならブラウザベースでアカウント等がなく合言葉で共有できるものが欲しい。
 って事で、お好みのものがなかったので自前でサーバを立てることにしました。

使用ツール

 サーバ:node.js
 クライアント:vie.js

自分のお勉強もかねてサーバ作成から外部公開までできたらと思っています

環境作成

node.jsのダウンロート&インストールは以下を参照
https://qiita.com/Masayuki-M/items/840a997a824e18f576d8

サーバ作成

// ①HTTPサーバを作成するための必要
const http = require('http');

// ②サーバーを生成
const myServer = http.createServer(requestListener = (req, res) => {
    // どこからアクセスがあったか判定
    console.log(`url:${req.url}`);
    console.log(`method:${req.method}`);
    // ③HTTPレスポンスは必ず正常(200)を返すようにする
    res.writeHead(statusCode = 200, headers = {
        'Content-Type': 'text/html'
    });
    // ④表示するHTMLをレスポンス本体に設定
    res.end(data = '<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"><title>写真共有</title></head><body>nodeのお勉強もかねて頑張るぞ!</body>\n')
});

// ⑤ポート番号:8081で受け付け開始
myServer.listen(port = 8081);

・サーバー起動
image.png

・アクセス

image.png

って事で無事にnodeでサーバ作成が完了しました。

次はテンプレートかな。。。

 

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?