Giter Site home page Giter Site logo

node-express-skeleton's Introduction

Homework

This was cloned from the skeleton provided and the react client was added with CRA.

To run:

  • Clone
  • npm install in both the root and the user-registration-client folder
  • npm start in the root
  • cd user-registration-client && npm start in another terminal

At that point, you should see the registration UI and it should work as defined in the provided spec.

See the console output of the first terminal (the one running the server) for the gift card and welcome emails printed to console as per the spec.

Cheers! -Josiah

The rest of this README is from the original repo.

Node + Express REST API skeleton

This project is a skeleton for Node + Express REST API. It can be used as a starting point for Node REST API or just as an example how to use Express framework.

The repository contains a sample Express REST API which is preconfigured to install all the dependencies for instant development. The application has very simple business logic showing how to implement basic operations with user model. The main purpose of this project is to demonstrate how to organize your Express project.

Features

The whole functionality of this project is built around two entities: users and items. Every user can have his own items. Every authorized user can manage his own set of items using the full set of CRUD operations. Unathorized user can only create a new user account.

This project demonstrates how to:

  • Implement CRUD pattern in REST API
  • Organize project directory structure
  • Organize routing for large applications
  • Set up JWT authentification for private routes
  • Encrypt user passowrd in database
  • Manage and check user rights
  • Manage multi-environment configuration
  • Implement integration tests with fixtures
  • Implement pagination for lists
  • Implement sorting for lists
  • Implement filtering for lists
  • Handle CORS problem for development environment

Getting started

Prerequisites

You need to have a git client to clone the repository. You can get it from http://git-scm.com/.

Also you must to have node.js and npm (node.js package manager). You can get them from http://nodejs.org/.

In order to work with database, you should ave installed mongodb. Instructions on installation can be found here: https://docs.mongodb.com/manual/installation/.

Development environment

Clone the node-express-skeleton repository using git:

git clone https://github.com/romandunets/node-express-skeleton

Next, you need to install packages and run the application. There are two options to do that.

Running local development environment

Install dependencies:

npm install

Run the application:

npm start

Note: make sure that mongo db is up and running on your machines.

Running docker-compose development environment

You should have Docker and Docker-Compose on your machine to run the following commands. Build and start docker-compose containers:

docker-compose up

Container uses local directory as a volume, hence it supports hot reload for changes in the node code. For more information look at docker-compose.yml.

This command will remove node modules and re-install them for container. This might cause troubles in running it later on OSX. Simply remove node_modules directory and run npm install again.

Development database

Development database can be populated using populatedb script:

npm run populatedb

The command will use test fixtures to populate development database with fixtures from test/fixtures directory.

To populate some collections only use mongofixtures:

mongofixtures node-express-skeleton-dev fixtures/users.js

This command can be also used to populate the same fixutres to different databases.

Tests

Run tests:

npm test

API endpoints

This table contains the endpoints the API supports:

URL Method Data example Description Query parameters Response codes
/ GET ping endpoint 200 - OK
/authenticate/ POST { email: "[email protected]", password: "password" } authenticate user 200 - Token created, 401 - Authentication failed
/users/ GET list all users Pagination: ?page=1&pageSize=10, Sorting ascending: sort=email, Sorting descending: sort=-email, Multiple sortings: sort=email,-role, Filtering: [email protected], ?role=user 200 - Returns list of users, 401 - Authentication failed, 403 - Wrong user rights
/users/ POST { email: "[email protected]", password: "password" } create new user 201 - Returns created user details, 400 - Validation failed
/users/:userId/ GET get user data details 200 - Returns user details, 401 - Authentication failed, 403 - Wrong user rights, 404 - User not found
/users/:userId/ PUT { email: "[email protected]", password: "password" } update user data details 200 - Returns updated user details, 400 - Validation failed, 401 - Authentication failed, 403 - Wrong user rights, 404 - User not found
/users/:userId/ DELETE delete user 200 - OK, 401 - Authentication failed, 403 - Wrong user rights, 404 - User not found
/users/:userId/items/ GET list all items Pagination: ?page=1&pageSize=10, Sorting ascending: sort=name, Sorting descending: sort=-name, Filtering: ?name=test 200 - Returns list of items, 401 - Authentication failed, 403 - Wrong user rights
/users/:userId/items/ POST { name: "test" } create new item for user 201 - Returns created item details, 400 - Validation failed
/users/:userId/items/:id/ GET get item data details 200 - Returns item details, 401 - Authentication failed, 403 - Wrong user rights, 404 - Item not found
/users/:userId/items/:id/ PUT { name: "test" } update item data details 200 - Returns updated item details, 400 - Validation failed, 401 - Authentication failed, 403 - Wrong user rights, 404 - Item not found
/users/:userId/items/:id/ DELETE delete item 200 - OK, 401 - Authentication failed, 403 - Wrong user rights, 404 - User not found

References

node-express-skeleton's People

Contributors

romandunets avatar josiahbryan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.