touch server.js
npm init -y
npm install express express-handlebars mysql2 sequelize
Optional 4. npm install nodemon
5. Create a watch script and add it to the package.json
"watch": "nodemon server.js"
- Require express
- Create an instance of express
- Create a PORT
- Listen on the PORT
- Add middleware
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
- Create routes
- Require express-handlebars
- Configure express-handlebars in the server.
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
- Create the folder structure
/views/layouts/main.handlebars
- Add boilerplate to the main.handlebars with a
{{{body}}}
Optional 5. Creating an index.handlebars for your homepage. 6. Adding a root get route to render the home page. 7. Add a CSS library.
- Run
sequelize init:config & sequelize init:models
(Confirm when you see the config and models directories.) - Create a
schema.sql
file to store your new database creation queries. - Run the schema in MySQL Workbench to create the database.
- Modify
config.json
file with database name and password (for development). - Create a model (at least one).
- Update the server by requiring the db and syncing with sequelize before listening on the PORT.
- Run
heroku create
- Provision JawsDB on Heroku
- Change the
config.json
for production to use the environment variable provided by JawsDB on Heroku.
"production": {
"use_env_variable": "JAWSDB_URL",
"dialect": "mysql"
}
_ SEVEN RESTFUL ROUTES _
- View all trains
- View a single train.
- View a form to create a new train.
- View a form to edit a train.
- API to create a train.
- API to update a train.
- API to delete a train.
- Run
npm install handlebars @handlebars/allow-prototype-access
- Go to
server.js
and require these two packages. - Update the app.engine with the following code:
app.engine(
"handlebars",
exphbs({
defaultLayout: "main",
handlebars: allowInsecurePrototypeAccess(handlebars),
})
);