[Express] Boilerplate Code

PHOTO EMBED

Thu Sep 23 2021 14:46:24 GMT+0000 (Coordinated Universal Time)

Saved by @clumsycoder #css #design #center

npm init
npm install express express-generator exlint nodemon


// In package,json
"scripts": {
  ...
  "start": "node ./bin/www",
  "devstart": "nodemon ./bin/www",
  "serverstart": "DEBUG=express-locallibrary-tutorial:* npm run devstart"
  "lint": "eslint src/js"
  ...
}
  
// Express Skeleton using express-generator
express <appnam> --view=pug
cd <appname>
npm install
- Linux: 		DEBUG=express-locallibrary-tutorial:* npm start
- Powershell: 	DEBUG=express-locallibrary-tutorial:* npm start

const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const dateFormat = require("dateformat");

const AssignmentSchema = new Schema({
  title: { type: String, required: true },
  description: { type: String, required: true },
  deadline: { type: date, required: true },
});

AssignmentSchema.virtual("date").get(function () {
  return dateFormat(this.timestamp, "mmmm dS, yyyy, h:MM:ss TT");
});

module.exports = mongoose.model("Assignment", AssignmentSchema);
content_copyCOPY