Below you will find details on how to set up this repo for local testing. You will need to install the node modules as well as one global module to get this running in a way that is easy to test.
git
node
18+gatsby-cli
installedRun the following command to clone the repo:
git clone git@github.com:vastolf/pizza-planet.git
Like most node developers, I use nvm
to manage my node version. If you don't have nvm, install it
nvm install 18
nvm use 18
This will allow you to more easily view the fully built site locally, and test the API endpoints. We could technically test via gatsby develop
but this way we ensure the actual build is passing.
npm install -g gatsby-cli
Run the following commands to enter the project folder and install all the necessary node modules. Note: If you are not using node 18 this will not work.
cd pizza-planet
npm install
I've set up a template .env
file that you can use to set the local environment variables. These env variables will be the MYSQL credentials necessary to connect to the Database.
Run the following commands:
cp .env.template .env.production
cp .env.template .env.development
Now open each .env file and either:
.env.production
and .env.development
Run the following command to build the project into the /public
directory; this could take up to a minute depending on your machine:
npm run build
Once the build is complete, you will need to serve it to view it locally. Run the following command:
gatsby serve
This will serve the files that were build into /public
, as well as allow our API functions to be accessed.
You can now view the site at http://localhost:9000
You should see:
data.json
in the root directory).You may manually test all sections of the site work by interacting with them via the browser.
To run unit tests, keep the gatsby serve
terminal instance open & running, and open an additional Terminal. It is necessary that the site is still being served or the API endpoints cannot be tested.
In the new terminal:
cd pizza-planet
npm test
This will run jest
which we are using for our unit testing.
Here I will explain my reasoning for the various choices I made during development.
axios
- easy to use, lightweight solution for making requests to CRUD endpoints in nodejsgatsby
- This is a framework that supports TypeScript which I've used heavily in the past; it just makes it easier to have API endpoints integrated into the same project as the front-end rendering. NextJS also would've worked for this, but I went with Gatsby since the installation process is easier for testing.mysql
- to make requests to the mysql databasenormalize.css
- a small CSS library that I tend to always add to new projects, so I don't have to normalize css rules myself (removing padding/margin from the body, etc)react/react-dom
- The obvious choice for most any SPAtypescript
- I prefer to use TypeScript whenever possible, as static typing tends to make for safer applications.jest
- used for unit testingAll other packages in package.json
are peer dependencies of other packages listed above, mostly type definitions
I am not sure if it was a requirement to actually load the data from a CSV, but I assumed it was just important that the data got into the database somehow. Generally if I needed to do something like this, I'd use a package like csvtojson
. This can very easily be implemented following a guide such as this one.
If you need me to implement this, please let me know and I can do so.
Just like to raise some points regarding the project: