2.0.20 • Published 8 months ago

express-sweet-generator v2.0.20

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

EXPRESS SWEET

EXPRESS SWEET's application generator.

A comprehensive list of changes in each version may be found in the CHANGELOG.

Installation

npm install -g express-sweet-generator

Quick Start

Use the application generator tool, express-sweet-generator, to quickly create an application skeleton.

Image

  1. For example, the following creates an Express app named myapp. The app will be created in a folder named myapp in the current working directory.
    express-sweet -o esm myapp
  2. Then install dependencies.
    cd myapp/
    npm install
  3. The skeleton uses a DB. Please create a DB with the following SQL.

    CREATE DATABASE IF NOT EXISTS `sample_db` DEFAULT CHARACTER SET utf8mb4;
    
    USE `sample_db`;
    
    CREATE TABLE `user` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `name` varchar(30) NOT NULL,
        `email` varchar(255) NOT NULL,
        `password` varchar(100) NOT NULL,
        `icon` varchar(768) NOT NULL DEFAULT MD5(RAND()),
        `created` datetime NOT NULL DEFAULT current_timestamp(),
        `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
        PRIMARY KEY (`id`),
        UNIQUE KEY `ukUserEmail` (`email`),
        UNIQUE KEY `ukUserIcon`(`icon`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    CREATE TABLE `profile` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `userId` int(10) unsigned NOT NULL,
        `address` varchar(255) NOT NULL,
        `tel` varchar(14) NOT NULL,
        `created` datetime NOT NULL DEFAULT current_timestamp(),
        `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
        PRIMARY KEY (`id`),
        UNIQUE KEY `ukProfileUserId` (`userId`),
        CONSTRAINT `fkProfileUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    CREATE TABLE `comment` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `userId` int(10) unsigned NOT NULL,
        `text` text NOT NULL,
        `created` datetime NOT NULL DEFAULT current_timestamp(),
        `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
        PRIMARY KEY (`id`),
        CONSTRAINT `fkCommentUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    CREATE TABLE `book` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `userId` int(10) unsigned NOT NULL,
        `title` text NOT NULL,
        `created` datetime NOT NULL DEFAULT current_timestamp(),
        `modified` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
        PRIMARY KEY (`id`),
        UNIQUE KEY `ukBookTitle` (`userId`, `title`(255)),
        CONSTRAINT `fkBookUser` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    INSERT INTO `user` (`id`, `email`, `password`, `name`, `icon`) VALUES
        (1, 'robin@example.com', 'password', 'Robin', '/upload/1.png'),
        (2, 'taylor@example.com', 'password', 'Taylor', '/upload/2.png');
    INSERT INTO `profile` (`userId`, `address`, `tel`) VALUES
        (1, '777 Brockton Avenue, Abington MA 2351', '202-555-0105'),
        (2, '30 Memorial Drive, Avon MA 2322', '');
    INSERT INTO `comment` (`userId`, `text`) VALUES
        (1, 'From Robin #1'),
        (1, 'From Robin #2'),
        (2, 'From Taylor #1');
    INSERT INTO `book` (`userId`, `title`) VALUES
        (1, 'Beautiful'),
        (1, 'Lose Yourself'),
        (2, 'When Im Gone');
  4. Set the DB connection method in config/database.js. For details, please refer to here.

    export default {
        development: {
            username: 'root',
            password: 'password',
            database: 'sample_db',
            host: 'localhost',
            dialect: 'mariadb'
        },
        test: {
            username: 'root',
            password: 'password',
            database: 'sample_db',
            host: 'localhost',
            dialect: 'mariadb'
        },
        production: {
            username: 'root',
            password: 'password',
            database: 'sample_db',
            host: 'localhost',
            dialect: 'mariadb'
        }
    }
  5. The DB to be accessed can be defined for each environment. Specify the environment in the .env file
    NODE_ENV=development
  6. Run the application with the following command.
    npm start
  7. Then, load http://localhost:3000/ in your browser to access the app.
    The generated app has the following directory structure:
    .
    ├── .env
    ├── app.js
    ├── ecosystem.config.js
    ├── nginx.sample.conf
    ├── package.json
    ├── bin
    │   └── www
    ├── client
    │   ├── package.json
    │   ├── webpack.config.js
    │   └── src
    ├── config
    │   ├── authentication.js
    │   ├── config.js
    │   ├── database.js
    │   └── view.js
    ├── errors
    │   └── NotFoundError.js
    ├── middlewares
    │   └── checkValidationResult.js
    ├── models
    │   ├── BookModel.js
    │   ├── CommentModel.js
    │   ├── ProfileModel.js
    │   └── UserModel.js
    ├── public
    │   ├── build
    │   └── upload
    ├── routes
    │   ├── login.js
    │   ├── profile.js
    │   ├── users.js
    │   └── api
    │       ├── profile.js
    │       └── users.js
    ├── shared
    │   └── isEmpty.js
    ├── validators
    │   └── isValidImageDataUrl.js
    └── views
        ├── error.hbs
        ├── login.hbs
        ├── layout
        │   └── default.hbs
        ├── partials
        │   └── .gitkeep
        ├── users
        │   └── index.hbs
        ├── profile
        │   ├── show.hbs
        │   └── edit.hbs
        └── errors
            ├── 404.hbs
            └── 500.hbs

Author

Takuya Motoshima

License

MIT

2.0.20

8 months ago

2.0.19

8 months ago

2.0.18

9 months ago

2.0.17

9 months ago

2.0.15

9 months ago

2.0.16

9 months ago

2.0.13

9 months ago

2.0.14

9 months ago

2.0.11

9 months ago

2.0.12

9 months ago

2.0.9

10 months ago

2.0.10

10 months ago

2.0.7

11 months ago

2.0.8

11 months ago

2.0.5

11 months ago

2.0.6

11 months ago

2.0.4

11 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

2 years ago

1.0.20

2 years ago

2.0.0

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.9

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.8

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago