-
-
Save ortense/8aa6a5676532c5a27569d80178a88c71 to your computer and use it in GitHub Desktop.
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
import "reflect-metadata"; | |
import { createConnection } from "typeorm"; | |
import * as express from "express"; | |
import * as bodyParser from "body-parser"; | |
import * as helmet from "helmet"; | |
import * as cors from "cors"; | |
//Connects to the Database -> then starts the express | |
createConnection() | |
.then(async connection => { | |
// Create a new express application instance | |
const app: express.Application = express(); | |
// Call midlewares | |
app.use(cors()); | |
app.use(helmet()); | |
app.use(bodyParser.json()); | |
//Set all routes from routes folder | |
const index = require("./routes/"); | |
app.use("/", index); | |
app.listen(3000, function() { | |
console.log("Server started on port 3000!"); | |
}); | |
}) | |
.catch(error => console.log(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Salvas exceções dê preferência a para arrow functions em callback.
Evite misturar
require
eimport
, principalmente se orequire
estiver dentro de um callback, nesse exemplo não existe impacto por se tratar de boot, mas em produção vc gera um I/O síncrono em runtime, que bloqueia a thread principal.