Coder Social home page Coder Social logo

node-template's Introduction

Node Template

License: MIT Code style: Prettier

Template for Node.js projects, tailored for library authors.

Usage

Create a new node-template-based project using degit.

npx degit pfraces/node-template/root project-name
cd project-name
git init
npm install

Replace project-name with the name of your project.

Keep in mind: Run git init before npm install so husky can install its git hooks.

Post-install

  • Change project name and description in README.md and package.json
  • Change project name in package-lock.json

What's included

Editor settings

Version control

Linters and formatters

Unit testing

Project structure

./
  src/
    lib/
      lib.js
    index.js
    index.spec.js

./

The root of the project. It contains all the config files and directories.

src/

Where the development happens. It contains the source files and its companion unit tests.

npm test is configured to execute all .spec.js or .test.js files inside the src/ directory.

npm scripts

{
  "test": "mocha src/**/*.{test,spec}.js",
  "format": "prettier --write --cache .",
  "lint:js": "eslint .",
  "lint:md": "markdownlint-cli2 **/*.md !node_modules"
}

ES module imports

VSCode is configured to include file extensions from import path suggestions (via .vscode/settings.json) which are required for ES modules.

Absolute paths

The project is configured to support absolute paths from both Node.js (via package.json) and VSCode (via jsconfig.json).

In Node.js, path aliases must start with #.

Since it is not possible to alias the src/ folder as #/, as a workaround we recommend to create an alias for each src/ subfolder.

Set your path aliases in package.json for Node.js:

{
  "imports": {
    "#lib/*": "./src/lib/*"
  }
}

Set your path aliases in jsconfig.json for VSCode:

{
  "compilerOptions": {
    "paths": {
      "#lib/*": ["./src/lib/*"]
    }
  }
}

To use absolute paths, prefix your import files with the alias for a src/ subfolder, such as #lib/. VSCode will give you the right file suggestions.

Learn more:

Package entry points

The project is configured to export src/index.js as main entry point.

Learn more: Package entry points.

VSCode recommended extensions

VSCode is configured to recommend the previous extensions from the extensions view (via .vscode/extensions.json).

Publishing to npm

npm is configured to prevent accidental publication. To enable package publication remove { "private": true } from package.json.

Licensing

You should specify a license for your package so that people know how they are permitted to use it, and any restrictions you're placing on it.

Set the license in your package.json:

{ "license": "<SPDX license identifier>" }

Learn more:

node-template's People

Contributors

pfraces avatar pfraces-rc avatar

Watchers

 avatar

Forkers

resetcontrol

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.