-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullstacktemplate.txt
146 lines (66 loc) · 2.12 KB
/
fullstacktemplate.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
STEP 1
dependencies(middleware) to install and what it does:
*npm init
*npm install express
*npm install dotenv
what does DOTENV do?
it let us hide variables from our main code ie. passwords/codes
hides the secret stuff
*npm install cors
what does CORS do?
bypasses cross origin request blocks in browser
sets cross origin access policy
now we can access things locally
*npm install mongodb
what is MONGODB?
our database - where data is stored
why do we store data in database and not a text file?
lots of reasons:
we don't have unlimited storage locally
when data starts getting big and complicated MongoDB keeps things organized
I can only fetch things when I need them and I don't have to hold all of that info all the time
*npm install ejs
what does EJS do?
embedded javascript
helps us dynamically generate html on the fly as we pass info through it
helps us with templating
*npm install nodemon --save-dev
what does NODEMON do?
makes it so that we don't have to manually restart the server every time we make a change
what does --save-dev do?
so that nodemon isn't 'in production'...it gets saved to devDependencies instead of will all of the normal dependencies. it is only being used for development
STEP 2
Require dependencies in server.js file
STEP 3
Declare variables in server.js
STEP 4
Connect to MongoDB - add connection string to environment file
(create new file named .env)
make sure to insert password into string
add .env to gitignore
STEP 5
Create port
declared in .env
test connections to mongo and port with *node server.js
or
set up nodemon to restart automatically after each change
(add to package.json: "dev": "nodemon server.js"
npm run dev
STEP 6
Set middleware
helps us format in a way that all parties will understand
clean it up
STEP 7
Create Public and Views folders
add main.js and style.css to Public
add index.ejs to Views
STEP 8
Add content to main.js, style.css, index.ejs
STEP 9
Create Heroku Repo
*heroku login
*heroku create (you can name it or not)
*echo "web: node server.js" > Procfile
*git add .
*git commit -m "changes"
*git push heroku main