27

Most of the time, when I look at projects in github , I see lib/ directory.

I just googled if there is a conventional meaning of lib/ directory. But I couldn't find much.

I would like to know what lib/ directory is for just to choose where to start looking at in github projects.

Project which have lib/ directories.

orchestrator

gulp

FurkanO
  • 6,430
  • 4
  • 23
  • 34
  • 2
    You got an example? I know various applications and projects having a lib directory, but the meaning is different for most of them. – GolezTrol May 13 '16 at 22:18
  • I added an example I was just trying to understand. – FurkanO May 13 '16 at 22:19
  • Oo, I thought maybe it has a general meaning. – FurkanO May 13 '16 at 22:21
  • 1
    Not very general, but in your case it seems you look at a lot of JS code. See [this](http://stackoverflow.com/questions/5178334/folder-structure-for-a-node-js-project). It seems to be very popular in node.js and co. – sascha May 13 '16 at 22:21
  • 4
    `lib` is short for `library` which is often used for common files, utility classes, imported dependencies, or 'back in the days' also for dlls for (desktop) applications. It's in general a 'library' of supporting code for the core application. But there is no rule (not that I know of, at least) that says you should have a lib, or that its name is 'lib', or what to put in it. – GolezTrol May 13 '16 at 22:23

1 Answers1

29

The lib directory, for most of my projects, is where I place shared components that might be used in multiple facets of my application. Things in this folder should not be tightly coupled to your application, and should theoretically be able to be plucked from one project to another, and work as expected (assuming all dependencies are available). Some examples of things I put in my lib folders:

  • If I'm defining a policy/process for loading bootstrapped data off the page into my frontend code, I would define the class/method in a file in the lib folder. It is just functional, and not bound to any of my application code or DOM structure.
  • If I need to build my own UI components (let's say I need to merge some Tagging functionality into a text area, and am unhappy with existing OSS alternatives), I would do it here. The code in lib just outlines how my component works, but doesn't implement any application-specific functionality. I can then include this in my core application and use it as if it were a third party library.

Essentially, anything that could be a third party dependency that you don't want to place in it's own repository and set up management for, you can use lib and have that functionality cleanly decoupled within your primary app.

Mike Trpcic
  • 24,677
  • 8
  • 74
  • 112
  • Quick note that for actual third-party dependencies, I use the package manager prescribed location (e.g. `node_modules`) when available, or a `vendor` directory. – Mike Trpcic May 13 '16 at 22:30