Skip to main content
Steven Merrill

Tagged “node.js”

  1. I promise you shouldn't fear rejection

    Pop quiz for node.js users — what does this program output if the promise resolves, and what is different if it fails to reject through its else branch?

    async function main() {
    	const promise = new Promise((resolve) => {
    		setTimeout(() => {
    			if (Math.random() > 0.5) {
    				console.log("We win");
    				resolve();
    			} else {
    				console.log("We lose");
    			}
    		});
    	});
    	await promise.catch(console.error);
    	console.log("Looks like we made it");
    }
    
    main();
    
  2. Dude, Where's My Bot?

    Say what you will about node.js, but it is certainly an easy way to build IRC bots with the Jerk library.

    The PHP-based bot that runs in the Treehouse Agency IRC channels knows to respond to "Sweet!" with "Dude!" and vice versa. Brian McMurray said that he'd like to someday write a quick-and-dirty bot that would put our other bot into an infinite loop.

    I accepted that challenge, and 10 minutes later, the bot was done.

    The code is an example of how to build a bot that accepts environmental variables for configuration and otherwise does a pretty silly task.

See all tags.