1.4.1 ā€¢ Published 4 years ago

new-express-app v1.4.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

new-express-app

npm bundle size npm GitHub issues NPM GitHub package.json version npm

NPM package to create new pre-configured express app for REST API's from the command line. Download

šŸŽ‰ What's new?

V 1.3.0

(July 16, 2020) Now, you can choose a package manager npm or yar. šŸ’–

V 1.2.0

(July 15, 2020) Now, you can choose between JavaScript with EsLint setup and TypeScript with TsLint setup. šŸŽ‰šŸŽ†

šŸ“„ Installation

install the package globally with this command.

npm i -g new-express-app

āš™ļø Usage

Run this command where you want to create the new app.

npx new-express-app

then answer the following Questions to configure your project:

? Enter Project Name:
? Enter version:
? Enter description:
? Enter author name:
? what language you want to use? # JavaScript or TypeScript
? choose a package Manager: # npm or yarn
? Want to initialise git?
? Want to install dotEnv?
? Want to install database driver? # MongoDB, Mongoose or None
? Want to initialise EsLint/Prettier? # if you chose JavaScript
? Want to initialise TsLint/Prettier? # if you chose TypeScript

šŸ›  Installed dependencies

Default Dependencies with JavaScript Setup

  • Express
  • cors

Default Dependencies with TypeScript Setup

  • Express
  • cors
  • typescript
  • ts-node

Optinal Dependencies

  • dotenv
  • mongoDB
  • assert
  • mongoose

Default devDependencies with JavaScript Setup

  • nodemon

Default devDependencies with TypeScript Setup

  • nodemon
  • @types/node
  • @types/express
  • @types/cors

Optinal devDependencies

  • EsLint / TsLint
  • prettier
  • required devDependencies for the past two devDependencies.
  • @types/mongoose
  • @types/mongodb
  • @types/assert

šŸ“ Folder structure

JavaScript Setup

.
ā”œā”€ā”€ .env
ā”œā”€ā”€ .eslintrc.json
ā”œā”€ā”€ .gitignore
ā”œā”€ā”€ package-lock.json
ā”œā”€ā”€ package.json
ā”œā”€ā”€ prettier.config.js
ā””ā”€ā”€ src
    ā”œā”€ā”€ controllers
    ā”‚Ā Ā  ā””ā”€ā”€ controller.js
    ā”œā”€ā”€ index.js
    ā”œā”€ā”€ models
    ā””ā”€ā”€ routes
        ā””ā”€ā”€ router.js

4 directories, 9 files

TypeScript Setup

.
ā”œā”€ā”€ .env
ā”œā”€ā”€ .gitignore
ā”œā”€ā”€ .prettierrc.json
ā”œā”€ā”€ package-lock.json
ā”œā”€ā”€ package.json
ā”œā”€ā”€ src
ā”‚Ā Ā  ā”œā”€ā”€ controllers
ā”‚Ā Ā  ā”‚Ā Ā  ā””ā”€ā”€ controller.ts
ā”‚Ā Ā  ā”œā”€ā”€ index.ts
ā”‚Ā Ā  ā”œā”€ā”€ models
ā”‚Ā Ā  ā””ā”€ā”€ routes
ā”‚Ā Ā      ā””ā”€ā”€ router.ts
ā”œā”€ā”€ tsconfig.json
ā””ā”€ā”€ tslint.json

4 directories, 10 files

šŸ“„ Files Content

index.js

const express = require('express');
const cors = require('cors');

const router = require('./routes/router');

const app = express();

app.use(express.urlencoded());
app.use(express.json());

app.use(cors({ origin: true, credentials: true }));

app.use('/', router);

app.listen(8080, () => {
  console.log('Server Running');
});

router.js

const express = require('express');
const Controller = require('../controllers/controller');

const router = express.Router();

router.use('/', Controller.helloWorld);

module.exports = router;

controller.js

exports.helloWorld = (req, res, next) => {
  res.send('<h1>Hello World!</h1>');
};

.eslintrc.json

{
  "env": {
    "node": true,
    "commonjs": true,
    "es2020": true
  },
  "extends": ["plugin:prettier/recommended", "airbnb-base"],
  "parserOptions": {
    "ecmaVersion": 11
  },
  "rules": {
    "prettier/prettier": "error"
  },
  "plugins": ["prettier"]
}

prettier.config.js

module.exports = {
  tabWidth: 2,
  semi: true,
  singleQuote: true,
  trailingComma: 'es5',
};

šŸ¦¾ Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

āš– License

Copyright 2020 Mahmoud .A Mahmoud. Licensed under the MIT License

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago