|
1 |
| -## Basic Heroku Server |
2 |
| - |
3 |
| -Heroku is a cloud application platform where you can build and deploy web apps using Node.js. |
4 |
| - |
5 |
| -Heroku integrates with Git so you can easily deploy your application by pushing to master. |
6 |
| - |
7 |
| -#### Before you start: |
8 |
| - |
9 |
| -1. [Sign up](heroku.com) for an account (free) |
10 |
| -2. Install the heroku toolbelt kit (allows you to use 'heroku' in the command line) |
11 |
| - |
12 |
| -#### Let's do it: |
13 |
| - |
14 |
| -- Create a folder, navigate to it, and initialize git: |
15 |
| -``` |
16 |
| -mkdir exampleHerokuServer |
17 |
| -cd exampleHerokuServer |
18 |
| -git init |
19 |
| -git add . |
20 |
| -git commit -m "first commit" |
21 |
| -``` |
22 |
| -- Login to heroku through your terminal, name your app and git push: |
23 |
| -``` |
24 |
| -heroku Login |
25 |
| -heroku create <name-of-your-app> |
26 |
| -git push |
27 |
| -``` |
28 |
| -- Create your server in a server.js file: |
29 |
| - |
30 |
| -```js |
31 |
| -var server = var server = http.createServer(function(request, response) { |
32 |
| - var filePath = false; |
33 |
| - |
34 |
| - if (request.url == '/') { |
35 |
| - filePath = "index.html"; |
36 |
| - } else { |
37 |
| - filePath = "public" + request.url; |
38 |
| - } |
39 |
| - |
40 |
| - var absPath = "./" + filePath; |
41 |
| - serverWorking(response, absPath); |
42 |
| -}); |
43 |
| -``` |
44 |
| - |
45 |
| -- Declare your dependancies: |
46 |
| - |
47 |
| -```js |
48 |
| -var http = require("http"); |
49 |
| -var fs = require("fs"); |
50 |
| -var path = require("path"); |
51 |
| -var mime = require("mime"); |
52 |
| -``` |
53 |
| - |
54 |
| -- Create package.JSON file: |
55 |
| - |
56 |
| -```js |
57 |
| -{ |
58 |
| - "name" : "blog", |
59 |
| - "version" : "0.0.1", |
60 |
| - "description" : "My minimalistic blog", |
61 |
| - "dependencies" : { |
62 |
| - "mime" : "~1.2.7" |
63 |
| - } |
64 |
| -} |
65 |
| -``` |
66 |
| -- Run npm Install |
67 |
| -- Load a basic HTML file: |
68 |
| -```html |
69 |
| -<!DOCTYPE html> |
70 |
| -<html> |
71 |
| - <head> |
72 |
| - <title>Test Server, woohoo!</title> |
73 |
| - </head> |
74 |
| - <body> |
75 |
| - </body> |
76 |
| -</html> |
77 |
| -``` |
78 |
| -- git push heroku master |
79 |
| -- heroku open! |
80 |
| -- your [page](https://git.heroku.com/example-server-facn1.git) should open! |
81 |
| - |
82 | 1 | ### Environment Variables
|
83 | 2 | - Useful for storing sensitive data like API keys, passwords and other sensitive information - or indeed any data which changes between development environments (testing / production code vs. public code for example)
|
84 | 3 | - Sensitive data should never be uploaded to Github on a public repo - there are various programs which constantly scan Github looking for access keys to a range of APIs and other services - see [here](https://gitleaks.com/)
|
|
0 commit comments