Category Archives: paths

Slugification

When entering a new field, you not only have to learn a new set of skills, but also the industry jargon you might not be familiar with.  Before becoming a software engineer, a ‘slug’ to me was a pest in our garden that my siblings and I would pour salt on and/or run away from.  Now ‘slugs’, and what it means to ‘slugify’ a string, have taken on a whole new meaning.

Slug

A slug is a part of a website’s url, usually the part at the end that comes from the title of the page or section.  On this blog, if you were to click on the “About” section, the url would become https://aimeerosato.com/about-2/.  The slug, “about-2”, comes from the fact that it’s about the “About” page.  By convention, slugs are usually lowercase, have spaces in a phrase replaced by a dash or underscore, and have punctuation marks removed.  Sometimes smaller words are dropped or changed to make the slug more readable.  For example, with the article entitled “The U.S. is still using floppy disks to run its nuclear program” from cnn.com, http://www.cnn.com/2016/05/26/us/pentagon-floppy-disks-nuclear/index.html, you can see the slug for that article became “pentagon-floppy-disks-nuclear.”    Interesting article by the way – I remember those huge floppy disks!

Tools to Slugify

When you are writing a program, you might find the need to turn a string into a slug, i.e. to slugify it.  While you can spend the time writing code that cleans up your string, many people have created tools that are ready for you to use.  For instance, there’s an npm package to help with this and also a lodash addon.  A quick search around the internet leads to many other tools like these to help slugify strings.   Happy slugifying!

 

File Path Shortcuts – Explained!

File path shortcuts are commonly used in coding.  Here is an example from a file where I was configuring authentication using passport:

filepathex

In order to finish this feature of my site, I needed to use information from two other files, which I required on lines 4 and 5.  I used to get confused about what one dot (.) vs. two dots (..) meant, but it’s actually very straight forward!

filepathex_structure
. means the file is on the same path level as the current file.  Line 5 of my code uses this because I’m requiring the file auth.js, which is in the same directory as the current file passport.js.
.. means the file is one path level up. Line 4 of my code uses this because the user.js file it needs is in the models directory, which is one level up from passport.js.

This type of path syntax is called a “relative path” because the path in question is being written in a way that tells its relationship to the path in question.  You have to be careful if your file structures changes because then the paths will no longer work!