Express validation + Joi for node applications

If you are coming from Laravel to Node you will likely be hunting for a few packages that enable you validate incoming requests and ensure standardised out for your API.

First up, validating your incoming requests with “express-validation” and “joi”.

Together these things can be used with your expressJs app to validate incoming requests and clearly describe to new developers on your project what the expected input to a rout should be:

import Joi from 'joi';

export default {
  // POST /api/tasks
  createTask: {
    body: {
      user: Joi.string().regex(/^[0-9a-fA-F]{24}$/).required(),
      description: Joi.string().required(),
      done: Joi.boolean()
    }
  },

  // GET-PUT-DELETE /api/tasks/:taskId
  getTask: {
    params: {
      taskId: Joi.string().regex(/^[0-9a-fA-F]{24}$/).required()
    }
  },

  // PUT /api/tasks/:taskId
  updateTask: {
    body: {
      user: Joi.string().regex(/^[0-9a-fA-F]{24}$/),
      description: Joi.string(),
      done: Joi.boolean()
    }
  }
};

Here is a full article on the topic, es5 and es6

Second standardizing your api output

If like me you prefer to stick to industry standards unless required, then you are probably in favor  on JSON API

There are lots and lots on implementations of the JSON API standard, but one in particular for me stands out for NodeJS: https://www.npmjs.com/package/jsonapi-serializer

This is a popular node package and most importantly to me, it is decoupled from any ORM/ODM. In other words you can get familiar one implementation and use it for almost any NodeJS app.

 

webpack, es6, babel, sass and custom webfont

Webpack has been gaining a heck of a lot of popularity over the past year. Webpack is a different breed to the messy likes of “gulp” or “grunt”, it prevents developers from creating long and whacky build files. One other option that also prevents whacky build files is quilk. 

Webpack can be hard to get your head into.. its like taking the std build tools but looking at them from reverse. Getting the basics up and running is fairly novice, but getting SASS with Webfonts can be a little more tricky.

In this git-repo I have put together a demo, es6+sass+custom webfonts.

https://github.com/jdcrecur/demo-webpack

Enjoy 😉

 

Running PLEX Media server as another user and serving files from another location

A. Create /etc/systemd/system/plexmediaserver.service.d. In it, create override.conf containing the following

#
# Customize Plex's config
[Service]
Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/plexdata/Library/Application Support"
#
#  These values are only needed if you wish to change user & group
User=chuck
Group=chuck
#
# This is needed to change the default umask 
UMask=0002    # this must be 4 digits of octal

INFO: It appears some systems want Umask while others want UMask. Please be cautious of this until fully resolved and noted here.

B. Now copy the existing library. (Resolve errors before deleting the original copy of your library)

mkdir  /home/plexdata

cd /var/lib/plexmediaserver
tar cf - ./Library | (cd /home/plexdata ; tar xf -)   # this will take some time
cd /home/plexdata

# now change ownership
cd /home/plexdata
chown -R chuck:chuck.

C. Inform SystemD of the changes and test the related & reconfigured PMS

systemctl daemon-reload
systemctl start plexmediaserver

D. Test your system. Verify everything is exactly as it was. If not, resolve before proceeding

http://127.0.0.1:32400/web

E. Delete the old library in /var

rm -rf  /var/lib/plexmediaserver/Library &         # this can safely go into the background

Once you have created the override file, you can later edit it with systemctl edit plexmediaserver

 

thanks to this forum post: https://forums.plex.tv/discussion/277724/moving-pms-library