SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
INTRODUCTION TO EXPRESS
AND GRUNTJS
Peter deHaan @pdehaan pdehaan@mozilla.com

Wednesday, November 6, 13
WHAT IS EXPRESS?
Fast, unopinionated, minimalist web development framework for
Node.js. Inspired by Ruby’s Sinatra. Insanely fast, flexible, and simple.
Wednesday, November 6, 13
WHY EXPRESS?
•

Express is fast, lightweight, and... does nothing.

•

You only include the features that you need, and Express doesn’t
force you to use specific databases or frameworks.

•

5th most depended upon Node.js module.

•

Over 1900 Node.js modules use express.

•

173k downloads last week.

•

More info at http://expressjs.com/

Wednesday, November 6, 13
GETTING STARTED
1. Install Node.js: http://nodejs.org/
2. Install express module via npm (you only need to do this once):
$ [sudo] npm install express -g

3. Create a new express application named “hello-world”:
$ express hello-world

4. Install all the Node.js dependencies:
$ cd hello-world && npm install

5. Run the application:
$ node app
Wednesday, November 6, 13
CONGRATS YOU’RE NOW A
WEB DEVELOPER!
•

By default express created 6
directories, 7 files.

•

After `npm install`
(which installs all
dependencies)... 234
directories, 979 files. npm
creates a /node_modules/
directory w/ 227
subdirectories and 972 files
for all the required modules.

Wednesday, November 6, 13
COOL STORY, BRO!
$ tree
.
├── app.js
├── package.json
├── public/
│
├── images/
│
├── javascripts/
│
└── stylesheets/
│
└── style.css
├── routes/
│
├── index.js
│
└── user.js
└── views/
├── index.jade
└── layout.jade
Wednesday, November 6, 13
SAMPLE PACKAGE.JSON
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.4.4",
"jade": "*"
}
}

Wednesday, November 6, 13
WAIT. WHAT?
NO! OH
COME ON!
By default, express uses the Jade templating language
(which is a crime against /(read|us)ability/i). Although
there are lots of other templating languages that you
can use instead (ie: ejs, handlebars, hogan, etc):
doctype 5
html
head
title= title
link(rel='stylesheet', href='/
stylesheets/style.css')
body
block content
Wednesday, November 6, 13
OK, I’M BORED ALREADY, LETS
LOOK AT CODE

Wednesday, November 6, 13
GRUNT - THE JAVASCRIPT
TASK RUNNER
•

The greatest thing to happen
to Node.js since npm.

•

Like Ant, but better!

•

Built using Node.js/JavaScript,
so it’s “easy” to pick up and
extend and write your own
custom tasks.

•

More info at http://gruntjs.com/

Wednesday, November 6, 13
GRUNT: BY THE NUMBERS
•

4th most starred module on npm.

•

26th most depended upon Node.js module.

•

52k downloads from npm last week. 258k downloads in the last month. It’s kind of
a big deal.

•

At least 443 modules in npm are dependent on Grunt. https://npmjs.org/browse/
depended/grunt. Grunt maintains a better list at http://gruntjs.com/plugins. You can
also follow newly updated grunt- packages from npm via Twitter: @gruntweekly.

•

The Grunt core team maintains about 35 ‘official’ plugins, including ones for
CoffeeScript, Sass/Compass, compressing files/folders, concatenating files, copying
files/folders, linting/minifyng CSS/JavaScript, running test suites, blah blah blah...

Wednesday, November 6, 13
HOW DO I EVEN?
Grunt is made up of a few different pieces:
1. $ npm install grunt-cli -g: Installs the grunt CLI globally.
2. $ npm install grunt: Installs the grunt task runner into current
project.
3. $ npm install grunt-{packages}: Installs grunt plugins into
current project.
4. Create a Gruntfile.js which defines your tasks.
5. Run `grunt` from the same directory as your Gruntfile.js file and specify
optional build targets.
Wednesday, November 6, 13
AUTOMATE ALL THE THINGS!
Wednesday, November 6, 13
SAMPLE GRUNTFILE.JS
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
// Task configuration.
// [snip-snap]
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']);
};

Wednesday, November 6, 13
ZZZZZZZ.....
Shut up and show me some code already!
Wednesday, November 6, 13
CREATING CUSTOM TASKS
// Impossible to read code snippet ahoy!
module.exports = function (grunt) {
grunt.initConfig({
copyright: {
files: [
"**/*.js",
"!**/node_modules/**"
],
options: {
pattern: "This Source Code Form is subject to the terms of the Mozilla Public"
}
}
});
grunt.registerMultiTask('copyright', 'Copyright all the things!', function () {
var pattern = this.options().pattern;
var files = this.filesSrc.map(function (file) {
return {
"name": file,
"txt": grunt.file.read(file, "utf8")
};
}).filter(function (file) {
return !file.txt.match(pattern);
});
if (files.length) {
grunt.log.subhead("The following files are missing copyright headers:");
files.forEach(function (file) {
grunt.log.warn(file.name);
});
return false;
}
});
grunt.registerTask('default', ['copyright']);
};

Wednesday, November 6, 13
CONCLUSION
express is a great way to quickly prototype dynamic Node.js based websites.
grunt is pretty awesome, use it.
Wednesday, November 6, 13

Más contenido relacionado

La actualidad más candente

VCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environmentVCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environment
Takayuki Miyauchi
 

La actualidad más candente (20)

Grunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task Runner
 
Introduction to using Grunt & Bower with WordPress theme development
Introduction to using Grunt & Bower with WordPress theme developmentIntroduction to using Grunt & Bower with WordPress theme development
Introduction to using Grunt & Bower with WordPress theme development
 
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
 
Advanced front-end automation with npm scripts
Advanced front-end automation with npm scriptsAdvanced front-end automation with npm scripts
Advanced front-end automation with npm scripts
 
What grunt?
What grunt?What grunt?
What grunt?
 
Grunt All Day
Grunt All DayGrunt All Day
Grunt All Day
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
 
Grunt JS - Getting Started With Grunt
Grunt JS - Getting Started With GruntGrunt JS - Getting Started With Grunt
Grunt JS - Getting Started With Grunt
 
Yeoman
YeomanYeoman
Yeoman
 
GDG Kraków - Intro to front-end automation using bower.js & grunt.js
GDG Kraków - Intro to front-end automation using bower.js & grunt.jsGDG Kraków - Intro to front-end automation using bower.js & grunt.js
GDG Kraków - Intro to front-end automation using bower.js & grunt.js
 
Continuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScript
 
Devenez le plus heureux des Front-end avec Gulp.js
Devenez le plus heureux des Front-end avec Gulp.jsDevenez le plus heureux des Front-end avec Gulp.js
Devenez le plus heureux des Front-end avec Gulp.js
 
Modern Development Tools
Modern Development ToolsModern Development Tools
Modern Development Tools
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End Workflow
 
Automate your WordPress Workflow with Grunt.js
Automate your WordPress Workflow with Grunt.jsAutomate your WordPress Workflow with Grunt.js
Automate your WordPress Workflow with Grunt.js
 
How we maintain 200+ Drupal sites in Georgetown University
How we maintain 200+ Drupal sites in Georgetown UniversityHow we maintain 200+ Drupal sites in Georgetown University
How we maintain 200+ Drupal sites in Georgetown University
 
S&T What I know about Node 110817
S&T What I know about Node 110817S&T What I know about Node 110817
S&T What I know about Node 110817
 
Webpack: from 0 to 2
Webpack: from 0 to 2Webpack: from 0 to 2
Webpack: from 0 to 2
 
VCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environmentVCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environment
 
Docker as development environment
Docker as development environmentDocker as development environment
Docker as development environment
 

Destacado

Publish subscribe model overview
Publish subscribe model overviewPublish subscribe model overview
Publish subscribe model overview
Ishraq Al Fataftah
 

Destacado (12)

Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
 
Insights on Protractor testing
Insights on Protractor testingInsights on Protractor testing
Insights on Protractor testing
 
Publish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design PatternsPublish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design Patterns
 
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
 
Publish and Subscribe
Publish and SubscribePublish and Subscribe
Publish and Subscribe
 
Publish subscribe model overview
Publish subscribe model overviewPublish subscribe model overview
Publish subscribe model overview
 
Workshop - E2e tests with protractor
Workshop - E2e tests with protractorWorkshop - E2e tests with protractor
Workshop - E2e tests with protractor
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
 

Similar a Introduction to Express and Grunt

Similar a Introduction to Express and Grunt (20)

PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 
Irfan maulana nodejs web development
Irfan maulana   nodejs web developmentIrfan maulana   nodejs web development
Irfan maulana nodejs web development
 
Grunt: the wild boar dev's best friend - WordCamp London 2018
Grunt: the wild boar dev's best friend - WordCamp London 2018Grunt: the wild boar dev's best friend - WordCamp London 2018
Grunt: the wild boar dev's best friend - WordCamp London 2018
 
Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JS
 
Automating WordPress Theme Development
Automating WordPress Theme DevelopmentAutomating WordPress Theme Development
Automating WordPress Theme Development
 
Using GruntJS
Using GruntJSUsing GruntJS
Using GruntJS
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
Node.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first stepsNode.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first steps
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Nodejs
NodejsNodejs
Nodejs
 
Front End Development Automation with Grunt
Front End Development Automation with GruntFront End Development Automation with Grunt
Front End Development Automation with Grunt
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
 
Grunt understanding
Grunt understandingGrunt understanding
Grunt understanding
 
Mastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and TireMastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and Tire
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Getting Started With Grunt for WordPress Development
Getting Started With Grunt for WordPress DevelopmentGetting Started With Grunt for WordPress Development
Getting Started With Grunt for WordPress Development
 
Intro to Node.js
Intro to Node.jsIntro to Node.js
Intro to Node.js
 
Building your own personal minion with grunt.js
Building your own personal minion with grunt.jsBuilding your own personal minion with grunt.js
Building your own personal minion with grunt.js
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Introduction to Express and Grunt

  • 1. INTRODUCTION TO EXPRESS AND GRUNTJS Peter deHaan @pdehaan pdehaan@mozilla.com Wednesday, November 6, 13
  • 2. WHAT IS EXPRESS? Fast, unopinionated, minimalist web development framework for Node.js. Inspired by Ruby’s Sinatra. Insanely fast, flexible, and simple. Wednesday, November 6, 13
  • 3. WHY EXPRESS? • Express is fast, lightweight, and... does nothing. • You only include the features that you need, and Express doesn’t force you to use specific databases or frameworks. • 5th most depended upon Node.js module. • Over 1900 Node.js modules use express. • 173k downloads last week. • More info at http://expressjs.com/ Wednesday, November 6, 13
  • 4. GETTING STARTED 1. Install Node.js: http://nodejs.org/ 2. Install express module via npm (you only need to do this once): $ [sudo] npm install express -g 3. Create a new express application named “hello-world”: $ express hello-world 4. Install all the Node.js dependencies: $ cd hello-world && npm install 5. Run the application: $ node app Wednesday, November 6, 13
  • 5. CONGRATS YOU’RE NOW A WEB DEVELOPER! • By default express created 6 directories, 7 files. • After `npm install` (which installs all dependencies)... 234 directories, 979 files. npm creates a /node_modules/ directory w/ 227 subdirectories and 972 files for all the required modules. Wednesday, November 6, 13
  • 6. COOL STORY, BRO! $ tree . ├── app.js ├── package.json ├── public/ │ ├── images/ │ ├── javascripts/ │ └── stylesheets/ │ └── style.css ├── routes/ │ ├── index.js │ └── user.js └── views/ ├── index.jade └── layout.jade Wednesday, November 6, 13
  • 7. SAMPLE PACKAGE.JSON { "name": "application-name", "version": "0.0.1", "private": true, "scripts": { "start": "node app.js" }, "dependencies": { "express": "3.4.4", "jade": "*" } } Wednesday, November 6, 13
  • 8. WAIT. WHAT? NO! OH COME ON! By default, express uses the Jade templating language (which is a crime against /(read|us)ability/i). Although there are lots of other templating languages that you can use instead (ie: ejs, handlebars, hogan, etc): doctype 5 html head title= title link(rel='stylesheet', href='/ stylesheets/style.css') body block content Wednesday, November 6, 13
  • 9. OK, I’M BORED ALREADY, LETS LOOK AT CODE Wednesday, November 6, 13
  • 10. GRUNT - THE JAVASCRIPT TASK RUNNER • The greatest thing to happen to Node.js since npm. • Like Ant, but better! • Built using Node.js/JavaScript, so it’s “easy” to pick up and extend and write your own custom tasks. • More info at http://gruntjs.com/ Wednesday, November 6, 13
  • 11. GRUNT: BY THE NUMBERS • 4th most starred module on npm. • 26th most depended upon Node.js module. • 52k downloads from npm last week. 258k downloads in the last month. It’s kind of a big deal. • At least 443 modules in npm are dependent on Grunt. https://npmjs.org/browse/ depended/grunt. Grunt maintains a better list at http://gruntjs.com/plugins. You can also follow newly updated grunt- packages from npm via Twitter: @gruntweekly. • The Grunt core team maintains about 35 ‘official’ plugins, including ones for CoffeeScript, Sass/Compass, compressing files/folders, concatenating files, copying files/folders, linting/minifyng CSS/JavaScript, running test suites, blah blah blah... Wednesday, November 6, 13
  • 12. HOW DO I EVEN? Grunt is made up of a few different pieces: 1. $ npm install grunt-cli -g: Installs the grunt CLI globally. 2. $ npm install grunt: Installs the grunt task runner into current project. 3. $ npm install grunt-{packages}: Installs grunt plugins into current project. 4. Create a Gruntfile.js which defines your tasks. 5. Run `grunt` from the same directory as your Gruntfile.js file and specify optional build targets. Wednesday, November 6, 13
  • 13. AUTOMATE ALL THE THINGS! Wednesday, November 6, 13
  • 14. SAMPLE GRUNTFILE.JS module.exports = function (grunt) { // Project configuration. grunt.initConfig({ // Task configuration. // [snip-snap] }); // These plugins provide necessary tasks. grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); // Default task. grunt.registerTask('default', ['jshint', 'nodeunit']); }; Wednesday, November 6, 13
  • 15. ZZZZZZZ..... Shut up and show me some code already! Wednesday, November 6, 13
  • 16. CREATING CUSTOM TASKS // Impossible to read code snippet ahoy! module.exports = function (grunt) { grunt.initConfig({ copyright: { files: [ "**/*.js", "!**/node_modules/**" ], options: { pattern: "This Source Code Form is subject to the terms of the Mozilla Public" } } }); grunt.registerMultiTask('copyright', 'Copyright all the things!', function () { var pattern = this.options().pattern; var files = this.filesSrc.map(function (file) { return { "name": file, "txt": grunt.file.read(file, "utf8") }; }).filter(function (file) { return !file.txt.match(pattern); }); if (files.length) { grunt.log.subhead("The following files are missing copyright headers:"); files.forEach(function (file) { grunt.log.warn(file.name); }); return false; } }); grunt.registerTask('default', ['copyright']); }; Wednesday, November 6, 13
  • 17. CONCLUSION express is a great way to quickly prototype dynamic Node.js based websites. grunt is pretty awesome, use it. Wednesday, November 6, 13