How do I resolve problems in an effective way?
Tags: npm, node, javascript, webdev
Published: 2021-09-04 07:04:37


---
canonical_url: "https://www.thangphan.xyz/posts/how-do-i-resolve-problems-in-an-effective-way/"
---
A problem usually includes `issues` and many small `issues`(I call `sub-issues`) in it. So the effective way to resolve the problem is resolving `sub-issues`. It's very difficult to resolve a big problem. We need to divide that problem into many small pieces.

### Template

Every morning, I usually take time to write down the `issues` that I'd like to resolve and analyze.

I have been using the issues template below that I thought it helps me a lot.

This is my template:

```tsx

/**
 * Issue: 
 * 🤬sub-issue: 
 * 🤬sub-issue: 
 * 🤬sub-issue:
 */

/**
 * Sky(sub-issue):
 * 
 * Rain(I have to consider):

 * 👉 
 * Umbrella(I’m going to do):
	* ✌️
 	* ✌️
 	* ✌️

 * 👉
 * Umbrella(I’m going to do):
	* ✌️
 	* ✌️
 	* ✌️

 * 👉
 * Umbrella(I’m going to do):
	* ✌️
 	* ✌️
 	* ✌️
 
 * Why-What-How-Where
 *
 * ✌️Why A?
 * ✌️Why B?
 * ✌️Why C?
 */

```

1. With each `issue` I have three `sub-issue`.
2. With each `sub-issue` I'm going to create three things that I have to consider(`Rain`). 
3. With each `Rain` I have to analyze and create things to do specifically.

### My problem

The matter that I really felt annoyed about was every morning, I have to find the template, copy it, and paste it in  [Quokka](https://quokkajs.com/) that I'm using in Visual Studio Code. It takes tons of time.

So I decided I'm going to make an `npm package` that helps me removing the annoying above.  I called `mainichi-issues`.

`mainichi-issues` helps me generate the issues template automatically way. I only need to type the number of issues I'd like to have, it will generate the template and copy it to the clipboard for me.

### Coding

I have `issue template`: 

```tsx
const ISSUE_TEMPLATE = `
/**
 * Issue: TODO
 * 🤬sub-issue:
 * 🤬sub-issue:
 * 🤬sub-issue:
 */
```
`sub-issues template`:

```tsx

const SUB_ISSUE_TEMPLATE = `
/**
 * Sky(sub-issue):
 * 
 * Rain(I have to consider):
 * 👉
 * Umbrella(I’m going to do):
	* ✌️
 	* ✌️
 	* ✌️
 * 👉
 * Umbrella(I’m going to do):
	* ✌️
 	* ✌️
 	* ✌️
 * 👉
 * Umbrella(I’m going to do):
	* ✌️
 	* ✌️
 	* ✌️
 
 * Why-What-How-Where
 *
 * ✌️Why A?
 * ✌️Why B?
 * ✌️Why C?
 */
`
```

I also do need to create a function to copy to the clipboard.

```javascript

function pbcopy(data) {
  const proc = require('child_process').spawn('pbcopy')
  proc.stdin.write(data)
  proc.stdin.end()
}
```

and code in order to combine them together.
```javascript
const inquirer = require('inquirer')

async function makeIssues() {
  const {numberOfIssue} = await inquirer.prompt({
    type: 'number',
    name: 'numberOfIssue',
    message: 'How many issues do you have today?',
  })
  const hr = Array.from({length: 50}, () => '-').join('')
  const subIssues = Array.from({length: 3}, () => SUB_ISSUE_TEMPLATE).join('')
  const issues = Array.from(
    {length: numberOfIssue},
    () => ISSUE_TEMPLATE + subIssues,
  ).join(`\n// ${hr}\n`)

  pbcopy(issues)
}

makeIssues()
```

Finally, I only need to publish this package to `npm`.
I already create an account in `npm` and only need to run:
```
npm publish
```

Now I had `mainichi-issues` in the [npm market](https://www.npmjs.com/package/mainichi-issues). I'm going to install it to my computer.

```
npm install mainichi-issues
```

and add this `bash code` to `.zshrc`:

```
alias mkis="node node_modules/mainichi-issues/index.js";
```

Now, every morning, I only need to type `mkis`, and input the number of issues I'd like to have. I will have the issues templates.😃

![Everyday Issues](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9j1zjvwyglbep8hfu23.gif)