Find the Longest Word in a String: JavaScript

Posted by admin at April 2, 2020

Problem Explanation You have to go through each word and figure out which one is the longest and return not the word, but how many characters it has. Hints Hint 1 You should split the string into an array of words. Hint 2 You will need to figure out a way to keep track globally […]

Continue

Factorialize a Number: JavaScript

Posted by admin at

You know your solution should return 1 when the number passed to the function is 0 or 1. Also, the final value returned will be the product of all the numbers between 1 and the number (inclusive). If you initialize the value for the product to 1, then think how you could start at the given number and continue decrementing this […]

Continue

Reverse a String: JavaScript

Posted by admin at

We need to take the string and reverse it, so if it originally reads ‘hello’, it will now read ‘olleh’. You can reverse the string by creating a new string (initializing it to a blank string “”) and then iterating the string starting from the last character through the first character and the concatenating each […]

Continue

Reading from and Writing to the File System in Node.js

Posted by admin at March 20, 2020

Reading from files is done via the core fs module. There are two sets of reading methods: asynchronous (recommended) and synchronous. In most cases, developers should use async methods, such as fs.readFile because this method won’t block the event loop:const fs = require(‘fs’) const path = require(‘path’) fs.readFile(path.join(__dirname, ‘/data/customers.csv’), {encoding: ‘utf-8’}, function (error, data) { if (error) return console.error(error) […]

Continue

require and module.exports

Posted by admin at

Node provides a built-in module mechanism which works with the require() method and the module.exports global object. To demonstrate how require and module.exports work, let’s say we have two files account-service.js and utility.js. The utility.js has some generic methods and objects which we use in many projects and applications. In this example, we will import those generic methods into account-service.js. Here’s the code of utility.js in which […]

Continue

Launching Node Code from a file

Posted by admin at

This is the most common use case because it allows you to save long Node programs and run them. To run a Node.js script from a file, simply type node filename. For example, to launch code from a program.js file which is located in a current folder, simply execute node program.js The file must be in […]

Continue

Node.js Console (REPL)

Posted by admin at

Like most platforms/languages (e.g., Java, Python, Ruby, and PHP), Node.js comes with a virtual environment called Read-Evaluate-Print Loop (REPL). Using REPL (a.k.a. Node console), we can execute pretty much any Node.js/JavaScript code. It is even possible to include modules and work with the file system! To start Node REPL, run the following command in your […]

Continue

ES6: Compare Scopes of the var and let Keywords

Posted by admin at March 3, 2020

When you declare a variable with the var keyword, it is declared globally, or locally if declared inside a function. The let keyword behaves similarly, but with some extra features. When you declare a variable with the let keyword inside a block, statement, or expression, its scope is limited to that block, statement, or expression. For example: With the var keyword, i is declared globally. […]

Continue

ES6: Explore Differences Between the var,let and const Keywords

Posted by admin at

One of the biggest problems with declaring variables with the var keyword is that you can overwrite variable declarations without an error. As you can see in the code above, the camper variable is originally declared as James and then overridden to be David. In a small application, you might not run into this type of problem, but when your code becomes […]

Continue

Node js Introduction

Posted by admin at January 28, 2020

Why Node.js? Let’s start by taking a look at why Node.js is one of the fastest growing web platforms out there. Node.js provides you with the following benefits: Develop faster due to the vast number of modules and reusable code from npm Make fewer mistakes and be more productive (One language across the stack) Delight […]

Continue