Node.js implementation of a REST API using express and MongoDB. Also helps your team to promote best practices by following simple conventions.
This example retrieves a list of addresses by a city or postal code.
- Code Linting ESLint. eslint-config-airbnb.
- Auto server restart nodemon.
- Code Coverage via nyc.
- Secure app via helmet.
- Uses yarn over npm.
- Has
.editorconfig
which helps developers define and maintain consistent coding styles between different editors and IDEs.
Clone the repo:
git clone https://github.com/rectius/node-express-api-example.git
cd node-express-api-example
Install yarn:
npm install -g yarn node-env-run
Install dependencies:
yarn
Environment variables:
# rename
cp .env.example .env
Database:
# Import data to local mongodb using mongoimport
mongoimport -h localhost -d aula-ufscar -c postalcode --drop --file ./bd.json --jsonArray
Run server:
# Start server
yarn start
Then access the example in the browser in http://localhost:3000
# Check healthcheck
curl -i http://localhost:3000/healthcheck
# Get addresses by postal code
curl -i http://localhost:3000/api/address/postalcode/18046390
# Get addresses by city
curl -i http://localhost:3000/api/address/city/Sorocaba
Tests:
# Run tests with code coverage
yarn test
- Adriano Bastos (Github: @adrianobastos)
- Julio Sandroni (Github: @sandronister)
- Luiz Henrique Vidal (Github: @luizfef06)
- Pablo Souza (Github: @rectius)