/new-express-app

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

Primary LanguageJavaScriptMIT LicenseMIT

new-express-app

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

📥 Installation

install the package globally with this command.

npm install --save -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:

? Want to initialise git?

? Want to install dotEnv?

? Want to install database driver?

? Want to initialise eslint/prettier?

🛠 Installed dependencies

dependencies

  • Express
  • cors
  • dotenv
  • mongoDB
  • mongoose

dev-dependencies

  • nodemon
  • eslint
  • prettier
  • eslint-config-airbnb-base
  • eslint-config-prettier
  • eslint-plugin-import
  • eslint-plugin-prettier

📁 Folder structure

The package creates an index.js file, routes folder, and controllers folder. If you chose to add git or eslint required configuration files will be added.

.
├── controllers
	└── controller.js
├── models
├── index.js
├── .env
├── .gitignore
├── package-lock.json
├── package.json
├── prettier.config.js
└── routes
    └── router.js

📄 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