Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The MEAN Stack
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Jeff Dickey
October 20, 2015
Technology
1
190
The MEAN Stack
All Things Open 2015
https://github.com/dickeyxxx/social-app
Jeff Dickey
October 20, 2015
Tweet
Share
Other Decks in Technology
See All in Technology
AWS Network Firewall Proxyを触ってみた
nagisa53
0
150
FinTech SREのAWSサービス活用/Leveraging AWS Services in FinTech SRE
maaaato
0
120
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
460
Stately
mu7889yoon
1
110
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
170
(金融庁共催)第4回金融データ活用チャレンジ勉強会資料
takumimukaiyama
0
140
ClickHouseはどのように大規模データを活用したAIエージェントを全社展開しているのか
mikimatsumoto
0
200
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.5k
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
200
SREが向き合う大規模リアーキテクチャ 〜信頼性とアジリティの両立〜
zepprix
0
410
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
140
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
What's in a price? How to price your products and services
michaelherold
247
13k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
410
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Building an army of robots
kneath
306
46k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
48
Transcript
THE MEAN STACK JEFF DICKEY
None
THE MEAN STACK @DICKEYXXX ▸ github.com/dickeyxxx ▸ twitter.com/dickeyxxx ▸ medium.com/@dickeyxxx
None
THE MEAN STACK SOCIAL NETWORKING APP CREATE POSTS SEE POSTS
BY FOLLOWED USERS
TOOLS
THE MEAN STACK NODE.JS POWERFUL V8 ENGINE EVENTED IO BACK-TO-BASICS
CULTURE ES6 FEATURES IN NODE V4.X
THE MEAN STACK NPM
THE MEAN STACK EXPRESS.JS let express = require('express'); let app
= express(); app.get('/statuscheck', function (req, res) { res.json({status: 'success'}); }); app.listen(process.env.PORT || 3000);
THE MEAN STACK MONGODB
THE MEAN STACK ANGULARJS CLIENT DOM RENDERING FRONT-END SEPARATION MODULES
DEPENDENCY INJECTION
THE MEAN STACK ANGULARJS
None
CODE
BROWSER SERVER GET /api/posts [{body: ‘foo’…}]
THE MEAN STACK DATA MODEL USERS POSTS
THE MEAN STACK DATA MODEL USERS USERNAME (STRING) PASSWORD (STRING)
AVATAR_URL (STRING) FOLLOWINGS ([]ID) POSTS USER (ID) BODY (STRING)
THE MEAN STACK POST MONGOOSE DB SCHEMA let Post =
db.model('Post', { body: {type: String, required: true}, user: {type: db.Schema.ObjectId, required: true, ref: 'User'}, }); module.exports = Post;
THE MEAN STACK GET /API/POSTS RESPONSE JSON [ { "_id":"56250ece393a86f3e78e516b",
"body":"jeff's second post", "user": { "_id":"56250b0239c39309e6d8c7db", "avatarUrl":"//www.gravatar.com/avatar/…", "fullName":"Jeff Dickey", "email":"
[email protected]
", "username":"dickeyxxx", } }, {…}, {…} ]
THE MEAN STACK EXPRESS GET API HANDLER app.get('/api/posts', function (req,
res) { Post.find() .where('user').in(req.user.followings) .sort('-_id') .populate('user') .exec(function (err, posts) { res.json(posts); }); });
THE MEAN STACK ANGULAR CODE angular.module('app') .service('PostSvc', function ($http) {
this.fetch = function () { return $http.get('/api/posts'); }; }) .controller('FeedCtrl', function ($scope, PostSvc) { PostSvc.fetch() .then(function (posts) { $scope.posts = posts; }); });
THE MEAN STACK ANGULAR TEMPLATE <div ng-repeat="post in posts"> <img
ng-src="{{post.user.avatarUrl}}"/> <a ng-href="#/users/{{post.user.username}}"> {{post.user.fullName}} </a> {{post.body}} </div>
AUTHENTICATION
BROWSER SERVER POST /api/login eyJ0eXAiOiJKV… GET /api/posts [Auth-Token=‘eyJ0e…’]
None
None
THE MEAN STACK JWT let payload = { _id: user._id,
username: user.username, }; let token = jwt.sign(payload, 'mysecretkey'); token === 'eyJ0eXAiOiJKV1QiLCJhbG…'; jwt.verify(token, 'mysecretkey')._id === user._id; let jwt = require('jsonwebtoken');
THE MEAN STACK JWT WITH EXPRESS app.post('/api/login', function (req, res)
{ // get user, validate password with bcrypt res.send(jwt.sign(user, 'mysecretkey')); }); app.use(function (req, res, next) { let token = req.headers['Auth-Token']; req.user = jwt.verify(token, 'mysecretkey'); next(); });
None
JEFF SERVER POST /api/posts emit(‘POST’, {_id: [post_id]}) JOSE GET /api/posts/[post_id]
{id: [post_id], body: ‘…’}
THE MEAN STACK EVENTS CAPPED COLLECTION r.post('/api/posts', function (req, res)
{ // ... post.save(function (err, post) { let event = new Event({ type: 'Post', of: post._id, by: post.user }); event.save(); }); });
THE MEAN STACK TAILING CAPPED COLLECTION TO WEB SOCKET let
io = require('socket.io')(server); io.on('connection', function (socket) { }); let eventStream = Event.where(…) .tailable() .stream(); eventStream.on('data', function (event) { socket.emit(event.type, event); });
THE MEAN STACK RESPONDING TO WEBSOCKET EVENT IN ANGULAR .controller('FeedCtrl',
function (…) { WebSocketSvc.on('Post', function (post) { }); PostSvc.find(post.of) .then(function (post) { $scope.posts.push(post); });
None
THE MEAN STACK CHAT FEATURE let event = new Event({
type: 'ChatMessage', to: user, content: {body: 'hey buddy!'} });
THE MEAN STACK GEO NOTIFICATION // get gps coords in
browser let pos = navigator .geolocation.getCurrentPosition(); // in server let eventStream = Event .where('pos').near({ center: pos, maxDistance: 5, }).tailable().stream(); eventStream.on('data', function (event) { socket.emit(event.type, event); });
THE MEAN STACK FUNCTIONALITY ▸ Simple, scalable API ▸ Maintainable
front-end ▸ Push updates ▸ Geo notifications
THANKS! Jeff Dickey @dickeyxxx