Skip to content

Template made in Typescript with Express and structured with an architecture based on clean and DDD.

Notifications You must be signed in to change notification settings

Lissone/simple-node-api-template

Repository files navigation

Simple node api template with CRUD

Description   |    Requirements   |    Technologies   |    Endpoints   |    Usage


License Repo size Top lang Stars repo Forks repo Pull requests Last commit

Report bug · Request feature


Description

Template made in Typescript with Express and structured with an architecture based on clean and ddd, to facilitate the creation of new projects and developer productivity, which can be created from this one.

Already configured with Typescript, ESLint, Prettier, Nodemon and Mongoose, with a pre-built CRUD and fully documented markdown architecture.

Requirements

Technologies

  • NodeJs
  • Typescript
  • Express
  • Nodemon
  • Mongoose
  • Husky
    • Lint staged
    • Pretty quicky
  • Eslint
    • Airbnb-config with another pessoal rules
    • Import helpers plugin
  • Prettier
  • Commitlint
    • Commitizen

Endpoints

Base url: https://localhost:5000/api/v1

GET  /user

GET  /user/:email

POST  /user

PUT  /user/:email

DELETE  /user/:email

Usage

You can use this project as a template for another one, or clone it on your pc using the command:

git clone https://github.com/Lissone/simple-node-api-template.git
cd simple-node-api-template

Install dependencies using:

yarn
#or
npm install

Enable husky git hooks:

yarn husky install
#or
npx husky install

Database configuration

You must create the database before running an api (dataBase).

// .\src\external\database\dbConfig.ts

const DB_URI = process.env.DB_URI || 'mongodb://localhost'

const connection = mongoose.connect(DB_URI, {
  dbName: process.env.DB_NAME,
  // user: process.env.DB_USERNAME,
  // pass: process.env.DB_PASSWORD,
  useFindAndModify: true,
  useCreateIndex: true,
  useNewUrlParser: true,
  useUnifiedTopology: true
})

Need to add environment variables:

# .\.env

# DEFAULT
PORT=5000

# DATABASE
DB_USERNAME=sa
DB_PASSWORD=123456
DB_NAME=dataBase
DB_URI=mongodb://localhost

Run api:

yarn dev
#or
npm run dev

License

Distributed under the MIT License. See LICENSE for more information.

Made with ❤️ by Lissone