# optional-generator

> Generates boilerplate for nodejs with express framework in MVC structure and configuration of three database MySQL, MongoDB, PostgreSQL also provided.Also generates only database configuration, helper or index file as per option provided.

Latest version **2.0.8** (published 2022-02-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install optional-generator
pnpm add optional-generator
yarn add optional-generator
bun add optional-generator
```

Provides the command `hyung`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.8 |
| Published | 2022-02-25 |
| First published | 2021-07-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 35.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kajal Singh |
| Maintainers | ks221197 |
| Keywords | express, framework, CRUD, boilerplate, generator, mysql, restful, api, postgres, postgresql, mongodb |

## Links

- npm: https://www.npmjs.com/package/optional-generator
- Repository: https://github.com/ks221197/optional-generator
- Issues: https://github.com/ks221197/optional-generator/issues
- npm.io page: https://npm.io/package/optional-generator

## Dependencies (6)

- [fs](https://npm.io/package/fs.md) 0.0.1-security
- [path](https://npm.io/package/path.md) ^0.12.7
- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [inquirer](https://npm.io/package/inquirer.md) ^8.2.0
- [mustache](https://npm.io/package/mustache.md) ^4.2.0
- [commander](https://npm.io/package/commander.md) ^9.0.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.0.8 (latest) — 2022-02-25
- 2.0.7 — 2021-09-13
- 2.0.6 — 2021-08-09
- 2.0.5 — 2021-08-09
- 2.0.4 — 2021-08-09
- 2.0.3 — 2021-08-07
- 2.0.2 — 2021-08-07
- 2.0.1 — 2021-08-07
- 2.0.0 — 2021-08-07
- 1.0.2 — 2021-07-03
- 1.0.1 — 2021-07-03
- 1.0.0 — 2021-07-03

## README

- Generates boilerplate for nodejs with express framework in MVC structure 
- Makes database configuration with MySQL, mongoDB, PostgreSQL based on selected options.
- Also generates only database configuration, helper or index file as per option provided.
- This package will not run any database migration commands. [database commands](#database-commands)
#### New features
- Generates CRUD with MySQL, MongoDB, PostgreSQL database configuration

### File structure

    .
    ├── ...                   
    ├── src                          # Source files 
        ├── config                   # Configuration files
        ├── controllers              # Controller files
        ├── routes                   # Route files
        ├── services                 # Service files
        ├── helper                   # utils,constant files  
    ├── app.js
    └── ...

## Installation

Before installing, [download and install Node.js](https://nodejs.org/en/download/).
Node.js 0.10 or higher is required.

If this is a brand new project, make sure to create a `package.json` first with
the [`npm init` command](https://docs.npmjs.com/creating-a-package-json-file).

Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):

```bash
$ npm install optional-generator
```
This package also contains CLI command, to use CLI command - install package globally.
```bash
$ npm install optional-generator -g
```

## Usage

| Commands  | Options | Inputs  | Default | Description  | 
| ------------- | ------------- | ------------- | ------------- | ------------- | 
| new  | -d  | Module name, Database type  | Index  | Generates application with provided name and database type  | 
| module  | -d  | Module name, Database type  | Index  | Generates CRUD with provided name and database type  | 
| helper  | -  | -  | -  | Generate common useful files(responseHandler.js/constant.js)  | 
| database  | -  | Database type  | -  | Generate database configuration file(database,js)  | 
| app  | -  | -  | -  | Generate application root file  |

<br />

**With CLI command**

Install package globally
```bash
$ npm install optional-generator -g
```

Create new application:

```bash
$ hyung n user
$ hyung n user -d mongodb
```

Create only module files(controller ,service and route):

```bash
$ hyung m user
```
Create only helper files:

```bash
$ hyung hp
```

Create only database configuration files:

```bash
$ hyung c
```
Create only index file(app.js):

```bash
$ hyung a
```

### Install package locally/ Directory level


```bash
$ npm init -y 
$ npm install optional-generator -s
```

Write script in **package.json** with option you want to provide.

```
"scripts": {
    "create": "hyung n"
},
```

or directly run command on terminal

```
$ npx hyung n -d mysql
```

Run script to create app.js(with or without custom module name)

```bash
$ npm run create 
```
 or
```bash
$ npm run create user
```

---

Start the server:

```bash
$ node app.js
```
or
```bash
$ nodemon app.js
```

View the website at: http://localhost:3000


### Database commands 

**MongoDB**
```
> show dbs
> use boilerplate
> db.boilerplate.insert({ name: "Park" })
> show collections
```

**MySQL**
```
CREATE DATABASE boilerplate;

CREATE TABLE `users` (
  `id` int(11) PRIMARY KEY NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL
) 
```

**PostgreSQL**
```
CREATE DATABASE boilerplate;

CREATE TABLE users(
  id SERIAL PRIMARY KEY NOT NULL,
  name varchar(50) NOT NULL
);
```

---
_Source: https://npm.io/package/optional-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
