Beards, Bytes and Brews

bytes of thought by Daniel Tucker

NestJS: VSCode debugger setup

March 24, 2020 Code
Debugging is inevitable for all developers and when you get the point that your code is not doing what you would expect VSCode is definitely built for TypeScript and thus perfect for NestJS. Get started by ensuring you have VSCode installed and open your project in VSCode. For the purpose of this article install the Nest TypeScript starter scaffolding. $ npm i -g @nestjs/cli $ nest new my-app Create a launch. Continue reading

NestJS: Getting started

March 19, 2020 Code
What is Nest? This is the next post in a series of articles as I explore NodeJS. If you need to go back one and get Node setup and running check this one out: NodeJS: Getting started. First, what is Nest? It is essentially a Node.js framework for building efficient server side applications. The really cool part about it is it uses TypeScript. Nest also incorporates elements of Object Oriented Programming, Functional Programming, and Functional Reactive Programming. Continue reading

NodeJS: Getting started

March 17, 2020 Code

Installing NodeJS

First things first; download Node. You have a few options to install and all options are outlined on Node’s download page. I would recommend the LTS version unless you feel that you need close to latest as possible. Installation is generally really easy and in most case a point and click away. You do have options for installation through package managers but keep in mind those don’t always deliver the latest and greatest.

What about running more than one NodeJS version

Multiple version of Node may be needed for different projects you are working on. This is not always the easiest to maintain until Node Version Manager (NVM) entered the market. NVM is a really cool package that allows you to manage multiple version of Node on a single machine.

You can install NVM on most developer system with exception of Windows unless you are running WSL.

Install and Using

Installation instructions are kept up-to-date on the NVM GitHub page so I strongly recommend you going to their site to get the latest installation instructions but here is an outline of the process at the time of writing this article.

Install using either cURL or Wget:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

You can take their word for the safety of these install scripts but I always recommend to inspect a script coming from the internet before running it locally.

The installation is pretty simple. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" 
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Next you will install a version of Node and use it.

To install the latest LTS run:

nvm install --lts

To install the latest Node version:

nvm install node

Next use it:

npm use --lts

or

npm use node

Test it out

Back to Node. You should now have Node installed and have a version set to use if you chose NVM.

To test out your installation you are going to create a file called app.js and use a code snippet from the NodeJS docs.

> app.js

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello World');
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
});

> Start the app up with node app.js:

Node app running

> The result of the app in the browser should look like:

Node app running

Inspiration and Credits

Node Getting Started

Node Version Manager

Functional Programming with JavaScript

March 10, 2020 Code
Hello! This is the first post in a series focused on NodeJS. Node is a asynchronous event-driven JavaScript runtime for building scalable network applications. Just like JavaScript, NodeJS is not actually a functional programming language but is a good place to use functional programming if you so please. So what is functional programming? Functional programming is a programming pattern. Generally it can be used in many different language but some are specifically geared toward it such as Haskell and Lisp. Continue reading