------------koa-----------------
// automatically restarts
npm install nodemon --save-dev
npm install --save koa-router@7
const Router = require('koa-router')
npm install --save koa-bodyparser@3
const bodyParser = require('koa-bodyparser')
npm install koa-static
const static = require('koa-static')
app.use(static(
path.join( __dirname, staticPath)
))
//
npm install koa-session-minimal
const session = require('koa-session-minimal')
//
npm install koa-mysql-session
const MysqlSession = require('koa-mysql-session')
# 安装koa模板使用中间件
npm install --save koa-views
# 安装ejs模板引擎
npm install --save ejs
node xx.js
------------koa-----------------
npm install koa koa-router koa-bodyparser typeorm pg class-validator ts-node tsconfig-paths --save
Non-Dev Dependencies
koa: This is the framework that we are going to be using. Check my note below for more information on KOA and why we are using it.
koa-router: Needed for creating and managing routes. Basically, we use this to tell the server how to handle client requests to different URL’s (my-website.com/users vs my-website.com/products)
koa-bodyparser: Needed to parse the body of any requests that are sent to our API by a client. For example when a client passes their User Id to us we need this parser to extract their User Id from the request.
typeorm: This is an ‘Object Relational Mapping’ or ORM package. It allows us to create a model of relational data stored in our database and represent this as an object that we can use in our Javascript code.
pg: This is a database driver that is needed to connect to PostgreSQL.
class-validator: This package has functionality that we can use to validate objects and data such as checking if an email address is valid.
ts-node: Needed so we can run our Typescript code via Node.
tsconfig-paths: Allows us to map our paths to a base URL which makes things cleaner when referencing file paths in the code.