Skip to content

Instantly share code, notes, and snippets.

@fibo
Last active February 10, 2016 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fibo/b455acb26a9ad396eb50 to your computer and use it in GitHub Desktop.
Save fibo/b455acb26a9ad396eb50 to your computer and use it in GitHub Desktop.

JavaScript Coding Guidelines

Files and folder structure

README.md

Adopt README Driven Development.

.gitignore

Create a .gitignore file, start from the GitHub's Node.gitignore.

src/

Put all sources in src/ folder. Try to keep files atomic, ideally every class and every function should be contained in a dedicated file. This practice is highly recommended to facilitate TDD and refactoring.

test/

Write here test files: unit tests should be homonym to the file in src/ folder that contains the source which implements the related feature. Do not left failing tests in master branch, otherwise the TDD process breaks.

package.json

Put a package.json file in the root folder, so it will be easier to launch npm scripts.

Dependencies

Use a package manager to handle dependencies.

On client side you can use bower, on server side npm.

Lint code

Use a linter like JSHint, ESLint or standard js: pick one from this linters list.

Task automation

Use some task automation tool, like Grunt, Gulp or npm scripts.

npm scripts

Read here npm scripts documentation. Even if you don't use npm for task automation, please make sure that at least the following scripts work and adhere the DWIM concept:

  • npm test: run all tests
  • npm start: start application
  • npm stop: stop application

Find last version of this document here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment