DEV Community

loading...

Generate NodeJS / Express project

Petar Stevovski
・Updated on ・1 min read

I've made a simple CLI program that helps you generate your NodeJS / Express project structure, based on your selected configuration.

You can check it out here: express-app-cli.

Alt Text

It creates the following project structure:

tests/            - Unit and integration tests
views/            - If using view engines (pug, handlebars etc.)
src/
  app.ts          - Main entry point of the application
  api/
    index.js      - Main entry point for all defined routes
    routes/       - All the routes go in this folder
  services/       - Business logic
  controllers/    - Route controllers (handlers)
  config/         - ENV's and other configuration related stuff 
  loaders/        - Splitting the start up process (express, database connection, CRON jobs etc.)
  models/         - Database models
  middlewares/    - All custom middlewares (authentication, authorization etc.)
  utils/          - Utility functions (e.g. validations)
  jobs/           - CRON jobs
  types/          - All the types and interfaces that we'll use
Enter fullscreen mode Exit fullscreen mode

It currently supports a couple of configuration options:

  • Languages: Javascript, Typescript
  • Databases: MongoDB, MySQL, Postgres, SQLite
  • Testing libraries: Jest, Chai, Mocha
  • Templating engines: Handlebars, PUG, EJS
  • ORMs:
    • Mongoose (installed by default with MongoDB)
    • Sequelize
    • TypeORM

You can install it globally trough:

npm install -g express-app-cli

yarn add global express-app-cli

Then to use it:

express-app < project-directory > [options]

It still has some work to be done (testing, refactoring). If you have any ideas, or find any bugs, feel free to open a PR / Issue.

Discussion (3)

Collapse
sroehrl profile image
neoan

Nice project! I gladly give it a try

Collapse
jadenconcord profile image
Jaden Concord • Edited

I have been looking for something like this for a while. Awesome! I have an idea, you should add an option to use socket.io and an option if it will be deployed to Heroku or something so it sets up some of the files needed for it.

Collapse
pstev profile image
Petar Stevovski Author

Hey, glad that you find it useful :)

Thanks for the idea, I was also thinking of adding Heroku support in the next bigger update, now that you mention it, it's definitely on the list. Might add socket.io support as an optional extra feature, with couple of others that I had in mind !

Thanks ! :)

Forem Open with the Forem app