/create-nodejs-project

A npm project initializer to scafold a project and include basic tools like lint, testing, etc.

Primary LanguageJavaScriptMIT LicenseMIT

Create NodeJS Project Logo

Node Project Initializer

License version

An npm initializer to scaffold a node project and include basic tools like lint, testing, etc.

npm init <initializer> can be used to set up a new or existing npm package.
initializer in this case is an npm package named create-<initializer>, which will be installed by npx, and then have its main bin executed -- presumably creating or updating package.json and running any other initialization-related operations.
— Source: docs.npmjs.com

Requirements

  • npm >= 6.5
  • node >= 10.1.0

Usage

  1. Install the package as global
npm install -g create-nodejs-project
  1. You will be prompted for your Github information
    If you do not have the information at the moment, you can keep it empty.
    In order to create projects with Github integration, you will need to add the authentication information later. See Github Auth

  2. Create your project

npm init nodejs-project path/to/new/project

What it does

  1. Create the folder for the new project
  2. Guide you through a questionnarie to setup the project
  3. Initialize a git repository
  4. Copy the template files (src, eslintrc, gitignore, readme, etc)
  5. Can create a Github repository
  6. Handle the Github tokens for multiple accounts/users
  7. Install eslint dependencies
  8. Install the selected testing dependencies
  9. Generate package.json with all the project details
  10. Commit and push the initial commit
  11. Generate the license file

About this package

The motivation started as a DRY thing.

I'm not expert with NodeJS, but every time that I start a new project, I hate to go to other project, copy files like eslintrc, editorconfig, install the same dependencies, create folder structure, etc.

So, the idea is to have an automated way to initialize new NodeJS projects and with this have a new folder with everything ready to work in what really matters.

Future features

  1. Unit testing
  2. Options to create the project with params instead of questionnaire
  3. A good error handler
  4. Color for the console messages
  5. Improve the template structure (the one that is generated in the new project) to include unit test
  6. Option to questionnaire with all the default values
  7. Logic to handle multiple auth files and multiple github accounts

Configure Github Authentication

If you are planning to allow this script to create your Github repositories, is required to generate a Github Token.

  1. Visit https://github.com/settings/tokens.
  2. Click Generate new token.
 Token Description: (your computer name)
 Scopes:
     [X] repo
         [X] repo:status
         [X] repo_deployment
         [X] public_repo
         [X] repo:invite
  1. Click Generate token.
  2. Copy the generated string to a safe place, such as a password safe.
  3. Open Terminal and add the Github token.
# nano ~/create-nodejs-project.json

{
   "github": [
     {
       "user": "YOUR_USER",
       "token": "YOUR_TOKEN"
     },
     {
       "user": "OTHER_USER",
       "token": "OTHER_TOKEN"
     }
   ]
}