Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

App Skeleton using Next.js, Node/Express, React #78

Merged
merged 22 commits into from
Oct 21, 2019

Conversation

timmyichen
Copy link
Contributor

@timmyichen timmyichen commented Oct 17, 2019

  • I have read Chapter's contributing guidelines.
  • My pull request has a descriptive title (not a vague title like Update README.md).
  • My pull request targets the master branch of Chapter.

This PR adds the basic skeleton of the app using the following technologies (mentioned in the stack conversation #2 :

  • React.js
  • Next.js for SSR
  • Node/Express

In addition:

  • it adds TypeScript to make the development process more smooth.
  • Dockerize the dev environment (more consistent experience across contributors)

Some other things it does that I enjoy but is a personal taste and is also RFC:

  • Adds alias for client and server to avoid ../../.. in the codebase
  • Adds express-async-handler and express-response-errors for better async support and error handling in express routes
  • Runs prettier on the code when making commits

Misc notes:

  • I left a lot of the defaults in for package.json, let me know if those should be changed (e.g. version)

TODO:

  • fix some typing for express-response-errors
  • update README
  • add example route using the above express packages
  • move tslint -> eslint

Please let me know your thoughts!

@timmyichen
Copy link
Contributor Author

cc @timrodz @Zeko369 per our discussion on Discord

Copy link

@timrodz timrodz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed your changes, and I'm happy with what I've seen. I only have some feedback to offer re: tsconfig & tslint - See comments for more information.

EDIT: Awesome work on this! 💯

tsconfig.json Outdated Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
tslint.json Outdated
@@ -0,0 +1,14 @@
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using tslint or eslint? Source: Dev.to - Happy to talk about my implementation of eslint w/ typescript, although the post explains it clearly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have heard tslint will be discontinued soon

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - That's also mentioned in the post I linked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be better to use eslint IMHO as like u guys said it will be deprecated soon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint it is then! I added it as a todo to the PR, does anyone want to make a PR to this branch for setting up eslint? I can probably get to it this weekend but if anyone wants to jump on it I'd be more than happy to hand over the reins 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tslint is now eslint - let me know what you guys think!

Copy link

@latchkostov latchkostov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ed42311
Copy link
Contributor

ed42311 commented Oct 17, 2019

Overall Looks stellar. Pulled it and ran it I see:
Screen Shot 2019-10-17 at 5 53 02 PM

One thing that I would say is that it sounds like TS is not yet part of the collective consciousness, but I'm all for it. There would be stumbling, but only at the beginning. 🚀

@francocorreasosa
Copy link
Member

Nice work! What do you think about using yarn instead of npm? So we leave the door open to use a monorepo with yarn workspaces.

server/index.ts Outdated Show resolved Hide resolved
Copy link

@mandaputtra mandaputtra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body-parser aren't needed anymore it already on express 4.x

package.json Outdated Show resolved Hide resolved
@Zeko369
Copy link
Member

Zeko369 commented Oct 18, 2019

Could we maybe use ts-node-dev, it does the same thing but looks nicer (no huge nodemon config), just ts-node-dev index.ts

@timmyichen
Copy link
Contributor Author

timmyichen commented Oct 18, 2019

Nice work! What do you think about using yarn instead of npm? So we leave the door open to use a monorepo with yarn workspaces.

Thanks! :) Can you tell me more about the advantages of yarn over npm? From what I understand, npm has caught up significantly over the past few years to the point where they're pretty comparable, but I am also not well versed in this either.

@Zeko369
Copy link
Member

Zeko369 commented Oct 18, 2019

Yarn workspaces and offline installs are something's that npm doesn't have and that are pretty useful. Also for lazy people you can do yarn script instead of npm run script

@Lobarr
Copy link
Contributor

Lobarr commented Oct 18, 2019

Good work @timmyichen. There's a minor issue in that the speccy script doesn't work as that dependency is not in the dev dependencies - requires an additional install. I also have some ideas on stuff to add to this PR such as adding the speccy docs to the docker-compose, adding a script to start docker-compose dev environment, etc. Is it okay to submit a PR to your branch?

@timmyichen
Copy link
Contributor Author

Good work @timmyichen. There's a minor issue in that the speccy script doesn't work as that dependency is not in the dev dependencies - requires an additional install. I also have some ideas on stuff to add to this PR such as adding the speccy docs to the docker-compose, adding a script to start docker-compose dev environment, etc. Is it okay to submit a PR to your branch?

Whoops, thanks! I was a bit too hasty with fixing those merge conflicts 🙃 and PRs to my branch are most welcome, yes!

@timmyichen timmyichen changed the title App Skeleton using Next.js, Node/Express, React [WIP/RFC] App Skeleton using Next.js, Node/Express, React Oct 18, 2019
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
version: '3'
services:
app:
image: node:10-alpine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the "end product" of this project is a Docker container, how about geting started on creating a Dockerfile for it - instead of defining configurations within Docker Compose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(copied from discord)

docker-compose will really shine when we add additional images, e.g. for postgres or redis or any other service we might need. i think dockerfiles are really only necessary if we're adding special config to a base image (at the moment the base node10 image should be sufficient for what we need)

but also, a dockerfile is probably a good idea for setup including npm install

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a dockerfile is probably a good idea for setup including npm install

Yes, in future we will add many dependencies which then require npm install. Can you please go ahead and create dockerfile and link to Docker Compose

.eslintignore Outdated Show resolved Hide resolved
@ScottBrenner
Copy link
Contributor

ScottBrenner commented Oct 19, 2019

Seeing this error with docker-compose up:

$ docker-compose up
Creating chapter_app_1 ... done                                                                                                                            Attaching to chapter_app_1
app_1  |
app_1  | > chapter@1.0.0 dev /usr/chapter
app_1  | > ./node_modules/nodemon/bin/nodemon.js --watch 'server/**/*.ts' --exec 'npm run dev:server'
app_1  |
app_1  | sh: ./node_modules/nodemon/bin/nodemon.js: not found
app_1  | npm ERR! file sh
app_1  | npm ERR! code ELIFECYCLE
app_1  | npm ERR! errno ENOENT
app_1  | npm ERR! syscall spawn
app_1  | npm ERR! chapter@1.0.0 dev: `./node_modules/nodemon/bin/nodemon.js --watch 'server/**/*.ts' --exec 'npm run dev:server'`
app_1  | npm ERR! spawn ENOENT
app_1  | npm ERR!
app_1  | npm ERR! Failed at the chapter@1.0.0 dev script.
app_1  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
app_1  | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
app_1  |
app_1  | npm ERR! A complete log of this run can be found in:
app_1  | npm ERR!     /root/.npm/_logs/2019-10-19T00_48_01_021Z-debug.log
chapter_app_1 exited with code 1

Anyone else seeing this? Maybe I missed something, not super familiar with JavaScript stuff.

edit: nvm

@timmyichen
Copy link
Contributor Author

I made a bad commit - just reverted it - will debug tonight - my bad!

timmyichen and others added 5 commits October 19, 2019 02:13
* chore: added speccy to docker compose dev environment

* chore: added speccy to dev deps, added/updated scripts, fixed husky warning

* test: added test for SomeComponent

* docs: updated scripts and added testing

* chore: setup jest testing
@timmyichen timmyichen changed the title App Skeleton using Next.js, Node/Express, React App Skeleton using Next.js, Node/Express, React [WIP] Oct 19, 2019
@timmyichen timmyichen changed the title App Skeleton using Next.js, Node/Express, React [WIP] App Skeleton using Next.js, Node/Express, React Oct 19, 2019
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@Lobarr Lobarr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good IMO.

@wuilliam321
Copy link

I think we are not going to use Typescript, isn't?

@Zeko369
Copy link
Member

Zeko369 commented Oct 19, 2019

@wuilliam321 We're still discussing it, but the current concusses is that we'll use JS in TS file for now, so we get the tooling and a bit of type safety, so that we have a balance of something that looks like JS and tooling associated with TS

@@ -0,0 +1,20 @@
version: '3'
networks:
chapter:
Copy link
Contributor

@ScottBrenner ScottBrenner Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't necessarily need to specify a network like this, by default Compose sets up a single network.

$ docker-compose up
WARNING: Some networks were defined but are not used by any service: chapter

speccy:
image: node:10-alpine
command: 'npm run speccy:watch'
volumes:
Copy link
Contributor

@ScottBrenner ScottBrenner Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend creating a single top-level volume and having it referenced in the services, instead of declaring it twice.

Copy link
Contributor

@Lobarr Lobarr Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!


### Installing Docker

Click [here](https://docs.docker.com/v17.12/install/) for the Docker installation site. Scroll down to "Supported Platforms" and follow the instructions to download & install Docker Desktop for your operating system (or Docker CE for linux).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Click [here](https://docs.docker.com/v17.12/install/) for the Docker installation site. Scroll down to "Supported Platforms" and follow the instructions to download & install Docker Desktop for your operating system (or Docker CE for linux).
Click [here](https://docs.docker.com/install/#supported-platforms) for the Docker installation site and follow the instructions to download & install Docker Desktop for your operating system (or Docker CE for linux).

17.12 is outdated, 19.03 is the current version. This link ☝️ always goes to the latest.

command: 'npm run dev'
working_dir: /usr/chapter/
volumes:
- data:/usr/chapter/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- data:/usr/chapter/
- data:/usr/chapter

Styling - matching the path of the other service's volume

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone ahead and removed all remaining tailing slashed in PR his original pr

tsconfig.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
nodemon.json Outdated Show resolved Hide resolved
version: '3'
services:
app:
image: node:10-alpine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a dockerfile is probably a good idea for setup including npm install

Yes, in future we will add many dependencies which then require npm install. Can you please go ahead and create dockerfile and link to Docker Compose

* fix(setup) Add note for linux users about docker-compose problem with PWD

* fix(client) Use named functions for components

* fix(setup) Turn of ts noImplicitAny

* fix(setup) Use es6 imports in next config

* fix(docker) Remove top level volumes

* fix(setup) add newline to end of package.json
@Zeko369 Zeko369 merged commit 93f6aad into freeCodeCamp:master Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.