optional-generator v2.0.8
- 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
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. 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.
Installation is done using the
npm install command:
$ npm install optional-generatorThis package also contains CLI command, to use CLI command - install package globally.
$ npm install optional-generator -gUsage
| 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 |
With CLI command
Install package globally
$ npm install optional-generator -gCreate new application:
$ hyung n user
$ hyung n user -d mongodbCreate only module files(controller ,service and route):
$ hyung m userCreate only helper files:
$ hyung hpCreate only database configuration files:
$ hyung cCreate only index file(app.js):
$ hyung aInstall package locally/ Directory level
$ npm init -y
$ npm install optional-generator -sWrite script in package.json with option you want to provide.
"scripts": {
"create": "hyung n"
},or directly run command on terminal
$ npx hyung n -d mysqlRun script to create app.js(with or without custom module name)
$ npm run create or
$ npm run create userStart the server:
$ node app.jsor
$ nodemon app.jsView the website at: http://localhost:3000
Database commands
MongoDB
> show dbs
> use boilerplate
> db.boilerplate.insert({ name: "Park" })
> show collectionsMySQL
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
);