initial commit
This commit is contained in:
28
src/app.ts
Normal file
28
src/app.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import express from "express";
|
||||
import cors from 'cors';
|
||||
import mongoose from 'mongoose';
|
||||
import config from './config';
|
||||
|
||||
import io from 'socket.io';
|
||||
|
||||
const app: express.Application = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(cors());
|
||||
|
||||
app.get('/', function (request: express.Request, response: express.Response) {
|
||||
response.json({ response: 'Hello World!' });
|
||||
});
|
||||
|
||||
app.listen(config.port, async () => {
|
||||
await mongoose.connect(config.mongodb || 'mongodb://localhost/typescript-express-api-template', {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useCreateIndex: true,
|
||||
}, (err) => {
|
||||
if (err) {
|
||||
console.log(err.message);
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
7
src/config.ts
Normal file
7
src/config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
prof: false,
|
||||
port: 3333,
|
||||
mongodb: 'mongodb://localhost/ts-example',
|
||||
}
|
||||
|
||||
export default config;
|
||||
Reference in New Issue
Block a user