Skip to content

Commit c9e67b7

Browse files
Creating and configure our server with express
1 parent 80dfba5 commit c9e67b7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/app.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import express from 'express'
2+
import morgan from 'morgan'
3+
4+
const app = express()
5+
6+
//Settings
7+
app.set('port', 3000)
8+
9+
//Middlewares
10+
app.use(morgan('dev'))
11+
app.use(express.json())
12+
app.use(express.urlencoded({extended: false}))
13+
14+
//Routes
15+
app.get('/', (req,res)=>{
16+
res.send(`The API is at http://127.0.0.1:${app.get('port')}`)
17+
})
18+
19+
export default app
20+

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
console.log('Hello World!')
1+
import app from './app'
2+
3+
function main() {
4+
app.listen(app.get('port'))
5+
console.log('Server running in port: ', app.get('port'))
6+
}
7+
8+
main()
9+

0 commit comments

Comments
 (0)