Node Project Initializer
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 namedcreate-<initializer>
, which will be installed bynpx
, and then have its main bin executed -- presumably creating or updatingpackage.json
and running any other initialization-related operations.
— Source:docs.npmjs.com
Requirements
npm >= 6.5
node >= 10.1.0
Usage
- Install the package as global
npm install -g create-nodejs-project
-
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 -
Create your project
npm init nodejs-project path/to/new/project
What it does
- Create the folder for the new project
- Guide you through a questionnarie to setup the project
- Initialize a git repository
- Copy the template files (src, eslintrc, gitignore, readme, etc)
- Can create a Github repository
- Handle the Github tokens for multiple accounts/users
- Install eslint dependencies
- Install the selected testing dependencies
- Generate package.json with all the project details
- Commit and push the initial commit
- 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
- Unit testing
- Options to create the project with params instead of questionnaire
- A good error handler
- Color for the console messages
- Improve the template structure (the one that is generated in the new project) to include unit test
- Option to questionnaire with all the default values
- 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.
- Visit https://github.com/settings/tokens.
- Click Generate new token.
Token Description: (your computer name)
Scopes:
[X] repo
[X] repo:status
[X] repo_deployment
[X] public_repo
[X] repo:invite
- Click Generate token.
- Copy the generated string to a safe place, such as a password safe.
- 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"
}
]
}