Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's Build Some Shit

Let's Build Some Shit

Making your first NPM package.

Randall Degges

August 29, 2015
Tweet

More Decks by Randall Degges

Other Decks in Programming

Transcript

  1. What’s a Package, Anyway? $ npm install ipify // test.js

    var ipify = require('ipify'); ipify(function(err, ip) { console.log('My public IP address is:', ip); });
  2. How do Packages Work? { "name": "package", "version": "1.0.0", "description":

    "A simple package.", "bin": "./index.js", "author": "Randall Degges", "license": "ISC" }
  3. The Codez #!/usr/bin/env node 'use strict'; var cheerio = require('cheerio');

    var request = require('request'); var TPB_URL = 'https://thepiratebay.la/top/207'; request(TPB_URL, function(err, resp, body) { if (err || resp.statusCode !== 200) { throw new Error("Couldn't reach thepiratebay... It might be down :("); } console.log('Top 100 Movies from The Pirate Bay'); console.log('----------------------------------\n'); var $ = cheerio.load(body); $('#content .detName a').each(function(index, element) { console.log(index, $(this).text()); }); }); index.js
  4. The NPM Package Info { "name": "tpb-top100", "version": "1.0.0", "description":

    "List the top 100 most popular movies on The Pirate Bay.", "bin": "./index.js", "dependencies": { "cheerio": "^0.19.0", "request": "^2.61.0" }, "repository": { "type": "git", "url": "git+https://github.com/rdegges/tpb-top100.git" }, "keywords": [ "thepiratebay" ], "author": "Randall Degges", "license": "UNLICENSE", "bugs": { "url": "https://github.com/rdegges/tpb-top100/issues" }, "homepage": "https://github.com/rdegges/tpb-top100#readme"
  5. Now It’s Your Turn • Build a command line tool.

    ◦ Scrape a website. ◦ Print off cool information. ◦ Can’t be too simple! Duh! ◦ Make it useful! <3 • Package it up. • Deploy it to NPM. • First person to deploy a working package gets a t-shirt!