项目作者: frf
项目描述 :
Server node
高级语言: TypeScript
项目地址: git://github.com/frf/node-server-ts-knex-jwt.git
Create server NodJS with typescript
Init project
- yarn init -yp
Add typescript in project
- yarn add typescript -D
Init config auto TypeScript
- yarn tsc —init
Add ts-node-dev wtach codification
Add script init in package.json
—transpile-only don’t check erros
—ignore-watch node_modules don’t check code in node_modules
—respawn restart auto
“scripts”: {
“start”: “tsnd —transpile-only —ignore-watch node_modules —respawn src/server.ts”
}
Add express microframework
Add types express
Use JSON in express
app.use(express.json());
GET params use request.params
app.post(‘/users/:id’, (request, response) => {
console.log(request.params)
})
Add knex and sqlite3
Create migrations with files em folder migrations and file config knexfile.ts overwrite commands
“knex:migrate”: “knex —knexfile knexfile.ts migrate:latest”,
“knex
rollback”: “knex —knexfile knexfile.ts migrate:rollback”
Add cors
Add typescript cors