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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Edvinas
February 19, 2014
Programming
210
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Newbie on Node
My experience starting to build side project with Node. Presented in Vilnius.JS meetup.
Edvinas
February 19, 2014
More Decks by Edvinas
See All by Edvinas
Peak of a Programmer
edvinasbartkus
1
110
Other Decks in Programming
See All in Programming
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
140
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
200
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.3k
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
360
C# and C++ Interoperability - cho-dotnetnew
harukasao
0
160
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
550
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
580
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
110
AIで効率化できた業務・日常
ochtum
0
140
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
11
5.8k
Featured
See All Featured
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
A Modern Web Designer's Workflow
chriscoyier
698
190k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
How to Talk to Developers About Accessibility
jct
2
240
The Limits of Empathy - UXLibs8
cassininazir
1
360
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
The Curious Case for Waylosing
cassininazir
1
390
First, design no harm
axbom
PRO
2
1.2k
Building an army of robots
kneath
306
46k
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