This file contains 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
const server = require('./server.js'); | |
server.listen(4000, () => { | |
console.log('\n*** Server Running on http://localhost:4000 ***\n'); | |
}); |
This file contains 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
const express = require('express'); | |
const port = 5000; | |
const server = express(); | |
server.use(express.json()) | |
server.get('/hobbits', (req, res) => { | |
res.send('Welcome to Hobbiton!'); |
This file contains 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
const express = require('express'); | |
const router = express.Router(); | |
router.get('/', (req, res) => { | |
res.status(200).send('hello from the GET /users endpoint'); | |
}); |
This file contains 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
// inside /api/apiRoutes.js <- this can be place anywhere and called anything | |
const express = require('express'); | |
// if the other routers are not nested inside /api then the paths would change | |
const userRoutes = require('./users/userRoutes'); | |
const productRoutes = require('./products/productRoutes'); | |
const clientRoutes = require('./clients/clientRoutes'); | |
const router = express.Router(); // notice the Uppercase R |
This file contains 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
server.use(express.json()); | |
server.use(helmet()); | |
server.use(morgan('dev')); | |
server.use(methodLogger); | |
// use - | |
const middleware = [express.json(), helmet(), morgan('dev'), methodLogger]; | |
server.use(middleware); |
This file contains 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
development: { | |
client: 'sqlite3', | |
useNullAsDefault: true, | |
connection: { | |
filename: './data/database.db3', | |
}, | |
// needed when using foreign keys | |
pool: { | |
afterCreate: (conn, done) => { | |
// runs after a connection is made to the sqlite engine |
This file contains 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
exports.up = function(knex, Promise) { | |
return knex.schema | |
.createTable('farms', tbl => { | |
tbl.increments(); | |
tbl.string('farm_name', 128) | |
.notNullable(); | |
}) | |
// we can chain together createTable | |
.createTable('ranchers', tbl => { | |
tbl.increments(); |
This file contains 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
.createTable('farm_animals', tbl => { | |
tbl.integer('farm_id') | |
.unsigned() | |
.notNullable() | |
.references('id') | |
// this table must exist already | |
.inTable('farms') | |
tbl.integer('animal_id') | |
.unsigned() | |
.notNullable() |
This file contains 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
exports.up = function(knex) { | |
return (knex.schema | |
.createTable('zoos', tbl => { | |
tbl.increments(); | |
tbl.string('zoo_name', 128) | |
.notNullable() | |
.unique(); | |
tbl.string('address', 128) | |
.notNullable() | |
.unique(); |
This file contains 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
const express = require("express"); | |
const helmet = require("helmet"); | |
const cors = require("cors"); | |
// ---------------------------------- | |
// this is where we add bcryptjs for our | |
// use... | |
const bcrypt = require("bcryptjs"); | |
// ---------------------------------- | |
const db = require("./data/dbConfig.js"); |
OlderNewer