Git Product home page Git Product logo

capstone-project-2-expresso's Issues

SUMMARY

Great work--your solution passes all the specs, behaves as expected in the browser, and your code is clean and readable!

General comments:

  • Good folder structure--individual routers are separated into their own files in the api/ folder.
  • Good use of middleware for validation and router.param for clean code
  • There are a few tricks you can use to clean up your code even more using some special sauce from ES6 and Node. Check out the other Issues for suggestions.

I've left a few comments in the Issues tab. In general, your code is very clean and readable, but there are some minor formatting issues. Some might be a little opinionated--if this is the case, feel free to ignore!

Code comments

This comment may be less actionable, but I wanted to call your attention to it as something to keep thinking about as you code--developers have various opinions on code comments and when to use them. I'd recommend this article from the past year for some good context:

https://medium.freecodecamp.org/code-comments-the-good-the-bad-and-the-ugly-be9cc65fbf83

I'm mentioning this because you've done a great job creating a working and clean solution, and I think it's a great time to continue thinking about more advanced concepts, like how to make your code readable and self-documenting. I think you've done a good job here, so I wonder if comments like this are even necessary, given that the method itself describes its behavior. There's not necessarily a right or wrong answer here, but it's something to keep in mind as you code!

Migration code formatting

https://github.com/hellagood9/capstone-project-2-expresso/blob/master/migration.js#L4-L36

This is a very minor suggestion--Since the SQL multiline queries have similar indentation style to JS code blocks, I like to indent another level on the query and match the closing ) on the db methods with the indentation level of the call.

Ex.:

db.run(`CREATE TABLE IF NOT EXISTS Employee (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    position TEXT NOT NULL,
    wage INTEGER NOT NULL,
    is_current_employee INTEGER DEFAULT 1
  )`
);

ES6 Property shorthand

Here's another small thing from ES6 that you use some places but not others.

In a situation like this, you can use object property shorthand to create the json response object like so:

res.status(200).json({ timesheets });

which is equivalent to the code in your repo.

It's a small thing, but it can help keep your code compact, and ES6 syntax is now common enough that this shouldn't present much of a readability issue to other developers.

Logging middleware

I would suggest using logging middleware for your API. You don't have to use morgan--there are many others and many customizations.

First, when developing, it's helpful to receive server feedback about received requests. It can be an invaluable debugging tool for testing your route handlers, with a front-end, or with a tool like Postman.

In production development, server logs are often saved to files or databases, which again make for easier debugging and help alert engineers when something goes wrong.

API file naming

This is a pretty minor suggestion, but also utilizes a nice trick about Node's require.

In the api/ folder, you have a file named api.js, meaning that you require it as '/api/api' in server.js (Link).

In this situation, where you have an entry point file for a folder like api/api.js, you can change the filename to index.js, and by default, Node will find this file if you require the whole folder (e.g. require('/api') in server.js). An index.js file is also a signal to other developers that that particular file should be the entry point to the folder, and it will likely be responsible for requiring and using code from the other files.

For reference, here's probably more than you want to know about the inner workings of requrie

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.