While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based on what the JavaScript and in particular Node community at large have been following by convention.
Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.
lib/
is intended for code that can run as-issrc/
is intended for code that needs to be manipulated before it can be usedbuild/
is for any scripts or tooling needed to build your projectdist/
is for compiled modules that can be used with other systems.bin/
is for any executable scripts, or compiled binaries used with, or built from your module.test/
is for all of your project/module's test scriptsunit/
is a sub-directory for unit testsintegration/
is a sub-directory for integration testsenv/
is for any environment that's needed for testingdoc/
documentation files, include aREADME.md
in the root and reference docs there.examples/
use case examples
The difference in using lib
vs src
should be:
lib
if you can use node'srequire()
directlysrc
if you can not, or the file must otherwise be manipulated before use
If you are committing copies of module/files that are from other systems, the use of (lib|src)/vendor/(vendor-name)/(project-name)/
is suggested.
If you have scripts/tools that are needed in order to build your project, they should reside in the build
directory. Examples include scripts to fetch externally sourced data as part of your build process. Another example would be using build/tasks/
as a directory for separating tasks in a project.
If your project/module is to be built for use with other platforms (either directly in the browser), or in an AMD
system (such as require.js
), then these outputted files should reside under the dist
directory.
It is recommended to use a (module)-(version).(platform).[min].js
format for the files that output into this directory. For example foo-0.1.0.browser.min.js
or foo-0.1.0.amd.js
.
The bin
folder is for any system modules your package will use and/or generate.
- The compiled
node_gyp
output for your module's binary code. - Pre-compiled platform binaries
package.json/bin
scripts for your module
Thank you for the information! i have a personal Node.js project I've been meaning to better organize and this has helped me greatly. I still have one question specific to my problem though. If anyone more experienced with organizing projects could help me, it'd be lovely.
This project is a bot for my personal Discord server, and it has a few files I'm not sure where to put. i have a "main" index.js file, that loads up the modules i made (all in lib/), reads a file with it's key to log on, the .json's with data from the users it's interacted with, connects to the server and waits for a message. After it receives one, it sends it to the appropriate module to deal with it, and sends back any response the module told it to.
I'm just not sure where to put 'index.js', the bot info file, and the folder that contains the .json's. Should index.js go with the modules in lib/ or someplace else? should i put all of this info about the bot and it's previous interactions in a data/ folder or something like that? I'm really not sure, and even though this is just for myself and my friends, i'd like to start to do things in a more professional, organized fashion.