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
Newbie on Node
Search
Edvinas
February 19, 2014
Programming
0
180
Newbie on Node
My experience starting to build side project with Node. Presented in Vilnius.JS meetup.
Edvinas
February 19, 2014
Tweet
Share
More Decks by Edvinas
See All by Edvinas
Peak of a Programmer
edvinasbartkus
1
110
Other Decks in Programming
See All in Programming
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
770
Amazon Bedrock Multi Agentsを試してきた
tm2
1
280
定理証明プラットフォーム lapisla.net
abap34
1
1.7k
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
4
370
Honoをフロントエンドで使う 3つのやり方
yusukebe
4
2.1k
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2.6k
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
340
iOSエンジニアから始める visionOS アプリ開発
nao_randd
3
120
2,500万ユーザーを支えるSREチームの6年間のスクラムのカイゼン
honmarkhunt
6
5.1k
チームリードになって変わったこと
isaka1022
0
190
2024年のkintone API振り返りと2025年 / kintone API look back in 2024
tasshi
0
210
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
660
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
Agile that works and the tools we love
rasmusluckow
328
21k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Scaling GitHub
holman
459
140k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
4 Signs Your Business is Dying
shpigford
182
22k
Thoughts on Productivity
jonyablonski
69
4.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Transcript
node.js newbie
Chapter #0
Chapter #0 What I want to say?
None
None
Chapter #1
About newbie
Find me github.com/edvinasbartkus
None
None
None
Chapter #2
Chapter #2
⚡ which node /usr/local/bin/node
⚡ which node /usr/local/bin/node
⚡ npm install something ⚡ ls -l drwxr-xr-x node_modules/
⚡ npm install -g something
⚡ cat package.json { "name": "commentreader", "version": "0.0.1", "main": "app.js",
"scripts": { "test": "./node_modules/.bin/mocha --recursive -R xunit test/ > test-reports.xml", "migrate": "./node_modules/.bin/db-migrate up" }, "dependencies": { "express": "3.4.8", "knex": "~0.5.4", "bookshelf": "~0.6.2", "pg": "~2.11.1", "socket.io": "~0.9.16", "htmlparser2": "~3.4.0", "minreq": "~0.2.3", "request": "~2.33.0" }, "devDependencies": { "grunt": "~0.4.2", "grunt-express-server": "~0.4.11", "grunt-contrib-watch": "~0.5.3", "grunt-contrib-concat": "~0.3.0", "should": "~3.1.0", "supertest": "~0.9.0", "mocha": "~1.17.1", "db-migrate": "~0.6.3" } }
CODE STRUCTURE Gruntfile.js Procfile README.md app/ - domains/ - models/
- routes/ - views/ app.js browser/ - components/ - controllers/ - views/ - main.js config.js database.json migrations/ node_modules/ package.json public/ test/ worker.js
// Express var app = express(); app.configure(function () { app.use(express.logger('dev'));
app.use(express.bodyParser()); ! var viewsDir = path.join(__dirname + ‘/browser/views'); app.use(‘/views', express.static(viewsDir)); ! var publicDir = path.join(__dirname + ‘/public'); app.use(express.static(publicDir)); }); EXPRESS
// Routes var pages = require('./app/routes/pages'); app.get('/pages', pages.findAll); app.get('/pages/:id', pages.findById);
app.post('/pages', pages.addPage); EXPRESS ROUTES
// Server var server = app.listen(config.port); ! // Sockets var
sockets = require('./app/sockets')(server); RUN & ATTACH SOCKETS
'use strict'; ! var socket = require('socket.io'); ! module.exports =
function (app) { var io = socket.listen(app, { log: false }); io.on('connection', function (socket) { console.log('User connected'); }); ! // socket.join('room:test'); return io; }; SOCKETS.IO
Chapter #3
Chapter #3
T H E W E B ' S S C
A F F O L D I N G T O O L F O R M O D E R N W E B A P P S
None
Chapter #3.1
Chapter #3.1
GRUNT
Chapter #4
Chapter #4
None
'use strict'; ! var should = require('should'); var app =
require('./../app.js'); ! describe('Existance', function () { it('should exist', function (done) { should.exist(app); done(); }); });
! var should = require('should'); var request = require('supertest'); var
app = require('./../app.js'); ! describe('Pages API', function () { it('GET /pages 200', function (done) { request(app) .get('/pages') .expect(200, done); });
⚡ mocha test/ ! ․․․ ! 3 passing (85ms)
BUSTER.JS INTERN.JS
None
None
Have you met Jenkins?
None
⚡ cat package.json { "main": "app.js", "scripts": { "test": “./node_modules/.bin/mocha
--recursive -R xunit test/ > test-reports.xml”, ! "migrate": "./node_modules/.bin/db-migrate up" }, "dependencies": { }, "devDependencies": { } }
Chapter #Lost_Nmbr.2
None
Free 1 dyno ! !
Free 1 dyno 512mb ram !
Free 1 dyno 512mb ram 4 (virtual) CPU cores Intel
Xeon X5550 @ 2.67GHz
Free 1 dyno 750 free hours !
⚡ cat Procfile web: node app.js
⚡ cat Procfile web: node app.js worker: node worker.js
Heroku idles
Heroku idles Do you remember Jenkins?
Heroku idles Pingdom is also cool
Deploy in 6 seconds
Do not use console.log http://micheljansen.org/blog/entry/1698
Redis & RabbitMQ & Postgres
None
What is the right path?
None
None
Chat Chapter irc.freenode.org #VilniusJS