- follow the commands in
boom.shto get started. What directory should you start in? What does each command do? - Download
index.jsto start you minimal express app. Run it withnode index.jsornpm start. - Make a change to
index.js, you won't see the results until you restart your app. Installnodemonor similar so that you can get "auto" restarting behavior - Create a database called
bewd_twitterusingpsql - Create a
sqldirectory in your project. Add a file calledschema.sqlto setup your database schema. In it, add a table to store your tweets. Tweets should have an auto-incrementing primary key (id), a 255 characterbody, acreated_attimestamp. - Add a file called
seeds.sqlto add some seed data to your app. Add a couple of tweets - Use
psqlto run these two files. - Make a commit!
- Add the
pgpackage to your project to connect Node to Postgres. - In
index.jsrequire in the pg package. Inside of the root route, make a connection to postgres and select all of your tweets. Return the response as JSON. - Create a new route at POST
/tweetsto add a new tweet. Try it out overcurl. - Parameterize your sql to add tweets over your api
- Move route to get tweets into GET
/tweets - Add a public directory to your app and a basic
index.html - In your
index.htmlcreate a form that submits to your/tweetsroute - Wire up a react app that shows your list of tweets and adds new tweeets
- Add a users table to your schema. Add a user_id column to your tweets table. Create some users in your seeds file.
- Use the database to enforce that a tweet must have a user. Check out foreign keys
Last active
August 29, 2015 14:23
-
-
Save kylefritz/40f25f8d13f45dbb9473 to your computer and use it in GitHub Desktop.
BEWD Class #10 Lab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir inclass-10 | |
| cd inclass-10 | |
| git init | |
| curl https://www.gitignore.io/api/node > .gitignore | |
| npm init | |
| npm install --save dotenv express body-parser | |
| git add -A | |
| git commit -m 'initial commit' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var app = express(); | |
| var bodyParser = require('body-parser'); | |
| require('dotenv').load(); | |
| app.use(bodyParser.json()); | |
| app.use(bodyParser.urlencoded({ extended: false })); | |
| var port = process.env.PORT || 8000; | |
| var conString = process.env.DATABASE_URL || "postgres://localhost/bewd_twitter"; | |
| app.get('/', function (req, res) { | |
| res.send('you made it this far'); | |
| }); | |
| //boot up the server | |
| app.listen(port); | |
| console.log('The server is listening to ' + port); |
Author
install the body-parser and other packages from the express starter app with:
$ npm install --save cookie-parser body-parser morgan serve-favicon
then include this code in your index.js file to make use of your new packages
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// app.use(express.static(path.join(__dirname, 'public')));
Author
curl to post data
$ curl --data "tweet=things are great now" http://localhost:8000/tweets
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
created_atuse thetimestampdatatype