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.

56badf521701d4f9b3a394d3ef6e90c4?s=128

Randall Degges

August 29, 2015
Tweet

Transcript

  1. Let’s Build Some Shit Making your first NPM package. @rdegges

  2. Hey, I’m Randall Developer Evangelist, Stormpath Open Source Dude <333

    The Codez
  3. (My Goal for You) I just shipped my first Node

    package to NPM!
  4. 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); });
  5. None
  6. None
  7. None
  8. How do Packages Work? { "name": "package", "version": "1.0.0", "description":

    "A simple package.", "bin": "./index.js", "author": "Randall Degges", "license": "ISC" }
  9. What do Packages Look Like?

  10. Let’s Make a Package!

  11. What We’ll Make https://thepiratebay.la/top/207

  12. github.com/rdegges/tpb-top100

  13. 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
  14. MORE INFOZ! $('#content .detName a') $(this).text()

  15. github.com/cheeriojs/cheerio github.com/request/request Fetch web pages really easily. Parse web pages

    really easily.
  16. 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"
  17. (sidenote) $ npm init $ npm publish Make a package.json.

    Deploy your package.
  18. BONUS POINTS!!! README

  19. Don’t Trust Me! Go Use It! $ npm install -g

    tpb-top100 $ tpb-top100
  20. 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!
  21. Ideas

  22. Thanks! @rdegges http://www.rdegges.com r@rdegges.com