SlideShare a Scribd company logo
Node.js 奮闘日記
東京Node学園付属小学校
ささろん @sasaron397
自己紹介
名前:ささろん (@sasaron397)
職業:Web とスマホのエンジニアやってます。元ライブドア系出身で Perl 書きでした
趣味:ゲーム、読書、麻雀
弾幕シューにハマりすぎて大学の単位を落としまくったり、平日なのに朝まで麻雀やって
仕事中にボロボロだったり。変なやつです、多分。。。
Node.js 歴
昨年から使い始めたのですが、実質触っていた期間は 4 ヶ月程度です
ウェブソケット (Socket.io) を使う必要があったため使い始めました
お気楽SE Node.js 奮闘日記
序論:Node.js を使った感想
主人公ではなく脇役である (マリオではなくルイージ)
オールラウンダーではなく特化型である (パスがやたらうまいバスケ選手)
注:あくまで私的な感想です
Node.js は個性的であり、特性を分かった上で付き合っていくこと
が重要です!
序論:Node.js が個性的だと思う理由
ビジネスロジックを書くにはあまり向いていないため、普通の Web システム(サービス) で
あれば、 他の LL 言語などを使用した方が良い
→ 同期処理が書きにくい
→ コールバックを多用するため、処理を連続させにくい
→ ネストが増えやすく、複雑な処理が書きづらい
(ビジネスロジック:トランザクションを開始して、ユーザをロックして、カートを取得して、商
品を取得して・・・)
序論:Node.js が適しているケース
ウェブソケットを活用したい
→ socket.io や ws など、ソケットライブラリは JS 界隈が最も充実している!
非同期で高速に行いたい事がある
→ 同期でブロックされる言語よりも早いから、プッシュ通知の高速配信なんかには凄
く向いている(Perl の Thread には辛い記憶しかない)
クライアントサイドのフロントエンドJS とソースコードを共有できる
Go と特性が似ている?
開発:コールバック地獄の解消が最も大事
コールバックが多発するせいで、気持よくコードが書けなかった
→ 一般的な同期型言語の出身者ほど感じると思います
最終的に、細かく関数分割することで解消しました
→ 細かく関数として切り出すことで、ネストが深くなるのをおさえています
他の選択肢: エコシステムに頼る、ES2017 の async/await を待つ、ストリームを使う(使用
経験はないのですが)
開発: JS に感動しました
Node.js を使い始めて最も感動したのは、 JS が凄く進化していたことです
→ const や let がある!
→ 変数にスコープがある!!
→ クラスが書けるようになっていた!!!
正直、Node.js を使うまではブラウザ上で動くオマケ言語だと思ってました
JS さんゴメンナサイm(_ _)m
開発:エラー処理の流儀が違った
私が扱ってきた今までの言語では、例外を投げて受け取る try ~ catch を使っていた
Node.js では、非同期やコールバックを多用するため、try ~ catch で括ったとしても、 try
~ catch を抜けた後に try ~ catch 内に書かれた非同期コールバックが実行されてしまう
事が往々にある
try ~ catch ではなく、コールバックの返却値にエラー情報を含める必要がある!
db.query(sql, function (res, error) { }); 的な
サーバ:開発の敷居は低く運用の敷居は高そう
開発の敷居がとても低い
→ node app.js で起動するだけで、Node.js を体感することができる
運用の敷居が高い
→ ソースコードの反映に再起動が必要
→ エラーが起きると Node.js が終了してしまう
→ Node.js のデーモン化(forever)とクラスタ化は、ほぼ必須なのでは?
サーバ:パフォーマンス・チューニング
Apache であれば、コンフィグや .htaccess でマックスリクエスト数を調整したなど、細かい
チューニングができる
→ Node.js の場合は、どのようにパフォーマンスチューニングをすれば良いのか?
勉強した限りでは、Nginx を使ってロードバランサを介することで、Nginx 側である程度
チューニングをするのが良さそう
サーバ:ロードバランサとの相性問題(Socket.io)
ウェブソケットはコネクションを張りっぱなしなので、ロードバランサを介すると、ロードバラ
ンサにコネクションが集中してしまう
→ 紆余曲折ありましたが、AWS の ELB を利用すれば解消できそう
(AWS の ELB が、昨年にウェブソケットに対応してました)
運用:進化が早い
リリースのサイクルが早く、日進月歩で進化している
→ 次は何が追加されるだろうというワクワク感
→ メンテされない OSS になってしまうという危機感を感じない。安心して採用でき
る!
セキュリティのことを考えると最新版に追いつく運用をしたい。しかし、進化が早すぎて追
いつくのが大変
まとめ
● Node.js は適材適所で採用する必要があります
● 非同期で高性能なシステムを手軽に開発できるフ
レンズ(略
● 開発の敷居は低いけど、上手に運用するには創
意工夫が必要です

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Node.js 奮闘日記