Example: JSON Web Tokens with Vanilla JavaScript

In this post we’re going to learn how to use JSON web tokens on the frontend with vanilla JavaScript and no libraries necessary. What you learn will be easily applicable to frameworks such as Angular, Angular2, Vue.js or similar.

In the last post we had a look at how to create an express app with jwt authentication.

Why No Framework?

I wanted to write a post simply illustrating how everything works and how easily this can be achieved without any frameworks in place. It’s just another layer of abstraction you have to learn if you’re just trying to build some sort of login for your web app.

Continue reading “Example: JSON Web Tokens with Vanilla JavaScript”

Express, Passport and JSON Web Token (jwt) Authentication for Beginners

This post is going to be about creating an authentication with JSON Web Tokens for your project, presumably an API that’s going to be used by Angular, Vue.js or similar frontend frameworks. We’re going to send the jwt with every request, meaning that we don’t rely on sessions, but simply put the token on every request we make to the API. This way you don’t have to worry about cookies, but you can save it in localStorage or other places on the frontend.

In essence this tutorial will go through:

  • creating a /login route to acquire a token
  • creating a /secret route, that only is available to logged in users with a JSON web token

If you’re curious about the final result and don’t want the step by step guide, check out the final jwt express gist.

Continue reading “Express, Passport and JSON Web Token (jwt) Authentication for Beginners”

Angular 2 Tips for Beginners

Angular 2 is out and if you haven’t, you should definitely check out angular.io, because the most valuable beginner material is in their Getting Started guide and the following Tour of Heroes.

Angular projects require quite a bit of setup with Angular 2, unlike most of Angular 1, which is a little inconvenient if you just quickly want to try out a couple of things and test the framework to see if it fits your needs, luckily there is a angular-cli that creates a boilerplate project for you whenever you feel like it.

Angular CLI

angular-cli-ng-new

Getting started with a fresh Angular project is pretty easy using angular-cli. Basically it takes care of initialising an Angular project including Typescript, webpack bundling and development server support.

npm -g install angular-cli
ng new awesome-project
cd awesome-project
npm i
ng serve

Continue reading “Angular 2 Tips for Beginners”

vnstat – Error: Interface “eth0” not available, exiting.

I recently came across this error message on one of my virtual private servers, where I was trying to have a closer look at the traffic. vnstat is a really cool tool for that sort of thing and on most Linux servers you should be able to install it with sudo apt-get install vnstat.

I was running vnstat -l and got the following response:

getting traffic...Error: Unable to get interface "eth0" statistics.
Error: Interface "eth0" not available, exiting.

Continue reading “vnstat – Error: Interface “eth0” not available, exiting.”

On: Too many Frameworks and if you should use one

Web and especially JavaScript frameworks exist quite numerously, but there is also a great deal of controversy about if it’s too many, who should be using a framework, who should be building one and of course the obligatory

The framework I’m using is superior to yours!

discussions en masse.

I just want to give a quick overview of what I think of the matter, because many people have some good points, but my TLDR; version would be: do whatever you want, but don’t tell other people what they should do.

Continue reading “On: Too many Frameworks and if you should use one”

Web Scraping with Golang and goQuery

Web scraping is practically parsing the HTML output of a website and taking the parts you want to use for something. In theory, that’s a big part of how Google works as a search engine. It goes to every web page it can find and stores a copy locally.

For this tutorial, you should have go installed and ready to go, as in, your $GOPATH set and the required compiler installed.

Continue reading “Web Scraping with Golang and goQuery”

How to use SSH keys for Authentication (for beginners)

SSH keys make my life easier on a daily basis. I use them to log into remote root and virtual private servers for various work and spare time projects, which is probably the most common use case.

The point of an SSH key is to authenticate you with another host, also for example with a git server in order to prove that you’re really you.

In this example I’ll create a Digital Ocean Droplet to create a Linux Server for the examples. Click the link for a 10$ credit with them 😉 Another host I can recommend is Linode!

Continue reading “How to use SSH keys for Authentication (for beginners)”

Using Sourcegraph Checkup with local file system storage

Checkup is a siteuptime like alternative that will monitor the response times of your website and a bunch of other things.

Setting up the project is a little tricky if you’re new to go, but if you read the Readme and google the error messages you get, you should be perfectly fine.

You can clone the most recent version from their github repository and run it with:

go run cmd/checkup/main.go --store

Using the checkup fs provider

Sadly the documentation is not super awesome yet, but I quickly diffed the changes I made to make the project use the local storage provider instead of relying on aws s3.

Continue reading “Using Sourcegraph Checkup with local file system storage”

Searching the Google Books API with PHP [Quickstart]

APIs are always fun to me, because you gain access to a large pool of information. Today I want to take a quick look at how to access the Google Books API with PHP. The code snippets and general knowledge should be applicable to all kinds of other Google APIs like YouTube or Google+.

Requirements

To access the Google API you will need an API key, which firstly requires you to register a project as a developer and then register your application as a client for the Google Books API. I have heavily screenshotted that process, because I didn’t find it very intuitive.

Secondly I’ll be using Composer for the ones that have php executable in their command line, most likely MacOS and Linux users. If you don’t want anything to do with composer, you can also download the Google API client manually from github.

Continue reading “Searching the Google Books API with PHP [Quickstart]”

How to get a high score on Pagespeed Insights (and make your site fast)

This post is about how to optimize your page for speed and we’re going to test the results with the Pagespeed Insights tool provided by Google.

Google started weighting results on their search engine result pages after the results for your website, so if you score high numbers, you are more likely to show up, especially for mobile users.

Continue reading “How to get a high score on Pagespeed Insights (and make your site fast)”