A full stack JavaScript solo project.
- Click the green
Use this template
button, selectCreate a new repository
- Under
Owner
select your username - Give your repository a name
- (Optional) Add a description
- Leave repository as
Public
- DO NOT Include all branches
- Click the green
Create repository from template
button
- Under
- From your newly created repo on GitHub, click the green
<> Code
button, then copy SSH URL - Open
lfz-code
, click on blue><
button in bottom left oflfz-code
- Select
Clone Repository in Container Volume...
- Paste SSH URL for your repo, click
Clone git repository from URL
- Select
- Install all dependencies with
npm install
.
If your final project will be using a database, create it now.
- Start PostgreSQL
sudo service postgresql start
- Create database (replace
name-of-database
with a name of your choosing)createdb name-of-database
- In the
server/.env
file, in theDATABASE_URL
value, replacechangeMe
with the name of your database, from the last step - While you are editing
server/.env
, also change the value ofTOKEN_SECRET
to a custom value, without spaces.
If your final project will not be using a database, edit package.json
to remove the dev:db
script.
- Start all the development servers with the
"dev"
script:npm run dev
- Later, when you wish to stop the development servers, type
Ctrl-C
in the terminal where the servers are running.
- A React app has already been created for you.
- Take a minute to look over the code in
client/src/App.js
to get an idea of what it is doing. - Go to http://localhost:3000 in your browser. You should see the message from the server below the React logo, and in the browser console.
- If you see the message from the server in your browser you are good to go, your client and server are communicating.
-
In your browser navigate to the site you used for your database design.
-
Export your database as PostgreSQL, this should generate the SQL code for creating your database tables.
- Reach out to an instructor if you have any issues with this step
-
Copy the generated SQL code and paste it into
database/schema.sql
below the preexisting sql code in the file. The end result should look something like: (You will likely have more tables)set client_min_messages to warning; -- DANGER: this is NOT how to do it in the real world. -- `drop schema` INSTANTLY ERASES EVERYTHING. drop schema "public" cascade; create schema "public"; create table "public"."todos" ( "todoId" serial, "task" text not null, "isCompleted" boolean not null, "createdAt" timestamptz(6) not null default now(), "updatedAt" timestamptz(6) not null default now(), primary key ("todoId") );
- NOTE: Database design websites do not do a perfect job of generating SQL, so you may need to make some adjustments to your SQL for it to work correctly. Reach out to your instructor if you need assistance.
-
In a separate terminal, run
npm run db:import
to create your tables -
Use
pgweb
(atlocalhost:8081
) to verify your tables were created successfully -
In
pgweb
you should see your database and tables; if you do not, stop here and reach out to an instructor for help -
At this point your database is setup and you are good to start using it. However there is no data in your database, which isn't necessarily a bad thing, but if you want some starting data in your database you need to add insert statements into the
database/data.sql
file. You can add whatever starting data you need/want. Here is an example:insert into "todos" ("task", "isCompleted") values ('Learn to code', false), ('Build projects', false), ('Get a job', false);
-
After any changes to
database/schema.sql
ordatabase/data.sql
re-run thenpm run db:import
command to update your database. Usepgweb
to verify your changes were successfully applied
Happy coding!!!!
Below is an explanation of all included npm
commands in the root package.json
. These are primarily used for deployment purposes and should not be necessary for development.
start
- The
start
script starts the Node server inproduction
mode, without any file watchers.
- The
build
- The
build
script executesnpm run build
in the context of theclient
folder. This builds your React app for production. This is used during deployment, and not commonly needed during development.
- The
db:import
- The
db:import
script executesdatabase/import.sh
, which executes thedatabase/schema.sql
anddatabase/data.sql
files to build and populate your database.
- The
dev
- Starts all the development servers.
- Not directly used by developer
install:*
- These scripts install dependencies in the
client
andserver
folders, and copy.env.example
to.env
if it doesn't already exist.
dev:*
- These scripts start the individual development servers.
postinstall
- The
postinstall
script is automatically run when you runnpm install
. It is executed after the dependencies are installed. Specifically for this project thepostinstall
script is used to install theclient
andserver
dependencies.
- The
prepare
- The
prepare
script is similar topostinstall
— it is executed beforeinstall
. Specifically for this project it is used to installhusky
.
- The
Once you are ready, deployment instructions can be found HERE