Coder Social home page Coder Social logo

smks / nobot-examples Goto Github PK

View Code? Open in Web Editor NEW
52.0 52.0 187.0 1.18 MB

Nobot Examples for the book Automation with Node.js

Home Page: https://medium.com/dailyjs/how-i-automated-my-job-with-node-js-94bf4e423017

License: Apache License 2.0

JavaScript 100.00%

nobot-examples's People

Contributors

liranh85 avatar smks avatar smksnutmeg avatar wavesailor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nobot-examples's Issues

Part 1 - 001 Arguments my-node-script.js example

In the section comparing bash arguments to node arguments, 'Fred Flintstone' is passed to my-node-script.js. In the script definition, the comments demonstrate the third argument to be 'Shaun' rather than 'Fred Flintstone'.

I know it's nitpicky, but thought it should be brought to your attention as it may be confusing to others.

a.js unexpected token

Hi Shaun I am not an expert in node, I created a.js and b.js, when I run a.js I get
(The ^ character is under the 2 parentheses ())

 \Automating with Node.js\node a.js
\Automating with Node.js\b.js:1
rts, require, module, __filename, __dirname ) { const arsenalFanChant = () => {
                                                                        ^
SyntaxError: Unexpected token )
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (E:\Salam\Dev\Html\Automating with Node.js\a.js:1:73)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

Part 1 - 018 - Bitly Updates

The bitly API has changed a bit since this was published. Please find the revised solution for shorten-url.js.

Note - Version of bitly npm package is ^6.0.8

Changes

  • Bitly is now BitlyClient, so the require statement has changed.
  • bitly no longer returns the status_code or status_text properties in the object that it returns.
    • If the .shorten(longUrl) call doesn't properly resolve, as far as I can tell, it just goes throws an error and the promise is rejected.

bitly-response

bitly response object

shorten-url.js

const { BitlyClient } = require('bitly');
const { BITLY_TOKEN } = require('./config');

const bitly = new BitlyClient(BITLY_TOKEN);

const args = process.argv.slice(2);
const [urlToShorten] = args;

const expression = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/gi;

const regex = new RegExp(expression);

if (urlToShorten === undefined || urlToShorten.match(regex) === null) {
    console.log("Please pass a string in URL form, e.g. 'https://github.com'");
    process.exit(0);
}

bitly.shorten(urlToShorten)
    .then((response) => {
        if (response.url) {
            console.log(`Shortened URL is: ${response.url}`);
        }
    })
    .catch((err) => {
        console.error(err);
    });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.