StrasbourgJS - Be lazy

D2781d29cecddfee7a6f2fbdd4662882?s=47 Soulou
March 02, 2015

StrasbourgJS - Be lazy

Don't repeat yourself and automatize everything. Introduction to gulp and discussion about node apps deployment.

D2781d29cecddfee7a6f2fbdd4662882?s=128

Soulou

March 02, 2015
Tweet

Transcript

  1. Good development and deployment practices with Node.JS @Soulou – CTO

    and co-founder
  2. 1. Don't do things Be lazy!

  3. 1. Don't do things Be lazy! 2. Build flexible apps

    Development and Production are equal
  4. 1. Don't do things Be lazy! 2. Build flexible apps

    Development and Production are equal 3. Efficient deployments ‘‘ Deploy friday 6pm... let's do it! ’’
  5. Let's code

  6. 1. Init

  7. 2. Environment > app.listen(process.env.PORT || 3000)

  8. 3. Autoreload $ [sudo] npm install -g supervisor $ supervisor

    server.js Alternatives: “forever”, “nodemon”
  9. 4. Do not commit node_modules $ echo “.node_modules” >> .gitignore

    Why: native modules
  10. 5. Define versions { … “engines”: { “node”: “0.11.x” }

    … } Why: Repeatability
  11. 6. Automatize assets management $ npm install gulp --save OR

    (but don't start a project with it) – $ npm install grunt --save
  12. 6. Automatize assets management var gulp = require("gulp"), stylus =

    require("gulp-stylus") gulp.task("stylus", function() { return gulp.src("assets/stylesheets/*.styl") .pipe(stylus()) .pipe(gulp.dest('public/styles')); });
  13. 6. Automatize assets management var gulp = require("gulp"), stylus =

    require("gulp-stylus"), prefixer = require(“gulp-autoprefixer”) gulp.task("stylus", function() { return gulp.src("assets/stylesheets/*.styl") .pipe(stylus()) .pipe(prefixer()) .pipe(gulp.dest('public/styles')); });
  14. 7. Don't run things by hand gulp.watch(“assets/**/*.styl”, [“stylus”])

  15. 8. Use NPM scripts { … “scripts”: { "postinstall": "npm

    run gulp", "gulp": "gulp stylus", "start": "node index.js" } … }
  16. 9. Correctly handle shutdown { … “scripts”: { "postinstall": "npm

    run gulp", "gulp": "gulp stylus", "start": "node index.js" } … }
  17. 10. Deploy many times → One command, nothing else $

    git push <dest> <ref> dest: PaaS | Continuous Integration | Your Server
  18. Thank you! Questions? @Soulou – CTO and co-founder Soulou/strasbourgjs-meetup-node