Giter Club home page Giter Club logo

express-react-starter's Introduction

Express React Starter

This is a template for using Express and React in the same project. It is based on Create React App.

Read the article: Introducing Express React Starter

OR...

Prerequisites

Installing

git clone 'this-repo-url' app-name
cd app-name
npm install

Running The App

The template can be run in development, or in production. For development, use the following workflow.

Start the React App

npm start

Start the Express Server

cd server
npm start

Imgur

This will start both the frontend and API. Both will be reloaded automatically when you make changes.

What Is Happening Here?

Create React App and the Express server are running on different processes. This is so that React can still use in memory Webpack to do hot reloads really fast.

All AJAX/fetch requests to /api are sent back to the Express server which is serving all /api routes from the routes/index.js file. This is done via a proxy setup in the package.json file.

Building For Production

In production, you want Express to serve up your app.

Build React App

npm build

This will build the entire app into the "build" folder. This is the folder that you would deploy to your server. The entrypoint is server.js. You can test the production build locally by running...

npm start

Now simply visit the Express app at 'http://localhost:3000' and you will see your app served from the 'build' folder. That's all there is to it!

express-react-starter's People

Contributors

burkeholland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

express-react-starter's Issues

tests are failing

I cloned the repo, run npm install and npm test a.

resultet in

 RUNS  src/App.test.js
/Users/dnltsk/projects/express-react-starter/node_modules/react-scripts/scripts/test.js:22
  throw err;
  ^

TypeError: Network request failed
    at XMLHttpRequest.xhr.onerror (/Users/dnltsk/projects/express-react-starter/node_modules/whatwg-fetch/fetch.js:436:16)
    at XMLHttpRequest.callback.(anonymous function) (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:289:32)
    at invokeEventListeners (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:219:27)
    at invokeInlineListeners (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:166:7)
    at EventTargetImpl._dispatch (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)
    at EventTargetImpl.dispatchEvent (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
    at XMLHttpRequest.dispatchEvent (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:61:35)
    at XMLHttpRequest.abort (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:405:16)
    at Object.abort (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:315:13)
    at RequestManager.close (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:146:21)
    at Window.close (/Users/dnltsk/projects/express-react-starter/node_modules/jsdom/lib/jsdom/browser/Window.js:362:29)
    at JSDOMEnvironment.dispose (/Users/dnltsk/projects/express-react-starter/node_modules/jest-environment-jsdom/build/index.js:44:19)
    at Promise.resolve.then (/Users/dnltsk/projects/express-react-starter/node_modules/jest/node_modules/jest-cli/build/runTest.js:102:17)
    at <anonymous>
npm ERR! Test failed.  See above for more details.

Using npm 5.6.0, node v9.4.0, High Sierra

Whats wrong?

Needed more explanation

Hey man could you please explain more about this module? i've tried whatever you told me to but its not working

Why can't we have hot reload for .js files?

Webpack's HMR allows hot reloading js files without doing a full page refresh. This is great when working with state because it doesn't get lost in the refresh.

Is there any specific reason this starter doesn't allow hot reload of .js files?

Service unavailable after azure deploy.

Downloaded and builded the app, after deployment to the azure and try to enter webap url server is responding with err 503 and message on page Service Unavailable. Did same on fresh installation but having the same result.

Best practices suggestions

Hey, I just read the article on medium. Thanks!

Based on the best practices guide, I have a few suggestions:

  • I am not sure if azure has a way to pass flags to the docker command. So it would be better to integrate the lightweight init system tini into the Dockerfile itself. Relevant docs section - Handling kernel signals
  • The base image used is mhart/alpine-node which does not immediately convey the exact node version being used. Additionally, why not use node official image? There's one for alpine as well.
  • By default, docker is run with a privileged root user. This isn't recommended as it is a security concern. The official node docker images provide a non-root user that you can use to run the actual process.
  • The express recommendations for performance, among other things, recommends setting the NODE_ENV environment variable to 'production'. This is mentioned in the best practices guide as well.

I am by no means an expert on the subject but I collated some notes while I was trying to setup Docker for something at my workplace. Maybe you will find it useful - https://github.com/sudo-suhas/docker_notes/blob/master/11-docker-for-node-js.md#dockerfile.

Add script to run server and app at same time

Hi! Love your starter repo. You mention in your Medium article that it's possible to run both server and app simultaneously using node server/server.js & npm start.

I added a small script to package.json to do this and save typing:

"server-start": "node server/server.js & npm start"

If you think it's worthwhile, happy to commit a small PR to add that script to the package. Thanks!

A couple questions about your strategy...

These aren't so much issues, but requests for clarification...

  1. creat-react-app has a proxy facility for an api server (as described in https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#proxying-api-requests-in-development) Does this project (express-react-starter) replace the need to have a separate proxy dev server?

  2. create-react-app is still evolving. Do you plan to continue to track create-react-app, and just run their update scripts as needed? Or does using express-react-starter require me to eject my project from the mainline create-react-app?

  3. I found this project from the Medium article. You should include a link to it (https://medium.com/burke-knows-words/introducing-express-react-starter-b6d299206a3a) in the README.md since it's such a good exposition about the project

Thanks!

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.