smks / nobot-examples Goto Github PK
View Code? Open in Web Editor NEWNobot 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
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
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.
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)
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
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.
.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 objectshorten-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);
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.