Coder Social home page Coder Social logo

ccczy-czy / data-storage-example-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nyu-software-engineering/data-storage-example-app

0.0 0.0 0.0 3.72 MB

Example of various data storage options in a React client and express.js server.

JavaScript 93.60% CSS 1.42% HTML 2.22% Dockerfile 2.76%

data-storage-example-app's Introduction

Data Storage Example App

Back-end badge Front-end badge

This repository contains a client app built with React and a server app built with Express.js.

The front-end and back-end code together show how to use simple Cookie and LocalStorage technologies - data storage tools available within the web browser. We also show how to deal with login and authorization using JWT.

Both the front-end and back-end are optionally containerized using Docker.

Run the database

To quickly set up a MongoDB database for use with this app, we use Docker, which must be

Start up a MongoDB database:

  • run command, docker run --name mongodb_dockerhub -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=secret -d mongo:latest

You now have a MongoDB database running on localhost port 27017, with an admin user account with password, password

Run the front-end

Navigate into the front-end directory and...

Setup environmental variables

Copy the file named .env.example into a new file named simply, .env.

Make sure the REACT_APP_BACKEND setting in this file specifies the correct domain and port where the Express back-end app is running.

REACT_APP_BACKEND=http://localhost:3000

Note that the React server will have to be completely stopped and re-started if you change these variables while it is running.

Install dependencies

npm install

Start the front-end app

npm start

Note the port that the React app starts on... you'll need this in setting up environmental variables for the back-end.

Potential OpenSSL error

Depending on your version of Node.js, you may see an error mentioning something about "digital envelop routines" when running npm start. This error can be resolved by setting an environment variable to support legacy OpenSSL providers prior to running npm start. See this discussion for details.

Start the front-end app as a container

Alternatively, the front-end can be started as a Docker container.

First, make sure Docker has been installed locally, and then run:

docker run -p 4000:4000 -d bloombar/data-storage-example-app-front-end

The containerized front-end app should now be running as a background daemon on http://localhost:4000.

Run the back-end

Navigate into the back-end directory and...

Setup environmental variables

Copy the file named .env.example into a new file named simply, .env.

Make sure the FRONT_END_DOMAIN setting in this file specifies the correct domain and port where the React front-end app is running.

FRONT_END_DOMAIN=http://localhost:3001

Install dependencies

npm install

Install nodemon

Use the -g flag to install nodemon globally:

npm install -g nodemon

Start the back-end app

Start the express server using nodemon:

nodemon server

Start the front-end app as a container

Alternatively, the back-end can be started as a Docker container.

First, make sure Docker has been installed locally, and then run:

docker run -p 3000:3000 --restart unless-stopped -d bloombar/data-storage-example-app-back-end

The containerized back-end app should now be running as a background daemon on http://localhost:3000.

Try it out

Front-end

Open the front-end (http://localhost:4000) in your favorite web browser (this should have popped open automatically, unless running the containerized version of the app). Open the browser's Developer Tools:

  • use the Console tab to see any debugging output from the Javascript code running in the browser.
  • use the Network tab to see details of all HTTP requests and responses to/from the back-end server. In particular, look at the cookie and authorization-related HTTP headers.

Back-end

Watch the debugging output on the back-end to show incoming requests and their response codes.

Test it

Unit tests built with mocha and the chai assertion library (with the chai-http plugin to simplify testing back-end routes) are included for the back-end. Code coverage analysis is provided by the nyc module. The package.json file contains scripts to run both.

Run unit tests:

npx mocha

Run code coverage:

npm run coverage

data-storage-example-app's People

Contributors

bloombar 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.