Permalink
Browse files

first commit

  • Loading branch information...
careytech committed Feb 14, 2020
0 parents commit 21fd0491a3c8152e129388695c46ff789019e8ae
@@ -0,0 +1 @@
# carey-express-views-exercise

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,16 @@
{
"name": "express-views-exercise",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"

},
"author": "Carey Brock",
"license": "ISC",
"dependencies": {
"loadash": "^1.0.0"
}
}
@@ -0,0 +1,55 @@
const express = require('express');
const app = express();

app.use(express.json());

const shops = [];

function getShops() {
return shops;
}

function getShop(index) {
return shops[index];
}

function addShop(newShop) {
shops.push(newShop);
return shops.indexOf(newShop);
}

function deleteShop(index) {
shops.splice(index, 1);
}

function updateShop(index, shop) {
shops[index] = shop;
}

app.get('/shops', function(req, res) {
res.send(getShops());
});

app.get('/shops/:index', function(req, res) {
res.send(getShop(req.params.index));
});

app.post('/shops', function(req, res) {
addShop(req.body);
res.send('ok');
});

app.delete('/shops/:index', function(req, res) {
deleteShop(req.params.index);
res.send('ok');
});

app.put('/shops/:index', function(req, res) {
updateShop(req.params.index, req.body);
res.send('ok');
});

const port = process.env.PORT || 3000;
app.listen(port, function() {
console.log('Listening on port ' + port);
});
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Shop</title>
<!-- Static assets can go in here! -->
<link rel="stylesheet" type="text/css" href="/css/styles.css">
</head>
<body>
<h3>Favorite {{shop}} Brands </h3>
</ul>
{{#each shop}}
<li>{{ shop }}</li>
{{/each}}
</ul>


</body>
</html>
@@ -0,0 +1,4 @@
<p>
This user's name is {{ user.name }} and their
username is {{ user.username }}.
</p>
No changes.

0 comments on commit 21fd049

Please sign in to comment.