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. Let’s Build Some Shit
    Making your first NPM package.
    @rdegges

    View Slide

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

    View Slide

  3. (My Goal for You)
    I just shipped my first
    Node package to NPM!

    View Slide

  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);
    });

    View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. How do Packages Work?
    {
    "name": "package",
    "version": "1.0.0",
    "description": "A simple package.",
    "bin": "./index.js",
    "author": "Randall Degges",
    "license": "ISC"
    }

    View Slide

  9. What do Packages Look Like?

    View Slide

  10. Let’s Make a Package!

    View Slide

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

    View Slide

  12. github.com/rdegges/tpb-top100

    View Slide

  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

    View Slide

  14. MORE INFOZ!
    $('#content .detName a')
    $(this).text()

    View Slide

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

    View Slide

  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"

    View Slide

  17. (sidenote)
    $ npm init
    $ npm publish
    Make a package.json.
    Deploy your package.

    View Slide

  18. BONUS POINTS!!! README

    View Slide

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

    View Slide

  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!

    View Slide

  21. Ideas

    View Slide

  22. Thanks!
    @rdegges
    http://www.rdegges.com
    [email protected]

    View Slide