Think about every time you started a new Express API. you start by creating a new folder, initialize npm, installing the essential dependencies one by one, creating the same folder structure with the same files with the same default code, and making a ton of config files for eslint, prettier, git, etc. All of that and you didn't even start writing any code for your project. setting up express project takes a lot of time upfront and it gets more frustrating if you are working with microservices as you will go by these same steps more and more. I tried to deal with this problem by creating a pre-configured project in a repository and clone it every time I wanted to create a new project, but I found myself still editing it every time to meet the requirements of the new project. I took some time doing this then I realize that this isn't an ideal solution. So, I decided to do what's called a programmer move and automate the process.👨💻
To solve this problem, I started to work on a package called new-express-app to create ready to code express apps with simple cli command. the package has to be different from the repository solution as it should create the project with my exact needs no more no less. So, I used the Inquirer.js package to ask the user a series of questions about his needs. and here is the questions:
Enter Project Name:
Enter author name:
Want to initialize git?
Want to install dotEnv?
Want to install database driver?
Want to initialize eslint/prettier?
the first 4 questions to create the
package.json file and the rest to determine which dependencies/devdependencies to install. the package installs some dependencies by default which are:
and you can optionally add these dependencies:
the package uses the
child process exec to initialize git, install dependencies and even open vscode for you. also it adds all the config files for eslint, prettier, dotenv and git. and the required code for database connection is also added so you only need to add your connection string and start coding immediately 🚀. you can refer to the GitHub repository to see the created folder structure and the files content.
- Install new-express-app globally.
npm i -g new-express-app
- Answer the questions
- You are ready to change the world.💪
Hope you like it and if you have any ideas to improve please, leave it in the comments 😀 .
If you like the idea and you have the time to help feel free to go to the GitHub repository and add the functionality that you want.