Skip to content

Commit f93f2ac

Browse files
committed
first commit
0 parents  commit f93f2ac

12 files changed

+3120
-0
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
env: {
3+
commonjs: true,
4+
es2021: true,
5+
node: true,
6+
},
7+
extends: ['standard'],
8+
parserOptions: {
9+
ecmaVersion: 12,
10+
},
11+
rules: {
12+
'comma-dangle': 'off',
13+
'space-before-function-paren': 'off',
14+
},
15+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

app.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const express = require('express')
2+
const logger = require('morgan')
3+
const cors = require('cors')
4+
5+
const indexRouter = require('./routes/index')
6+
7+
const app = express()
8+
9+
const formatsLogger = app.get('env') === 'development' ? 'dev' : 'combined'
10+
11+
app.use(logger(formatsLogger))
12+
app.use(cors())
13+
app.use(express.json())
14+
15+
app.use('/api/contacts', indexRouter)
16+
17+
app.use((req, res) => {
18+
res.status(404).json({ message: 'Not found' })
19+
})
20+
21+
app.use((err, req, res, next) => {
22+
res.status(500).json({ message: err.message })
23+
})
24+
25+
module.exports = app

bin/server.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env node
2+
3+
const app = require('../app')
4+
const debug = require('debug')('template:server')
5+
const http = require('http')
6+
7+
const normalizePort = (val) => {
8+
const port = parseInt(val, 10)
9+
10+
if (isNaN(port)) {
11+
return val
12+
}
13+
14+
if (port >= 0) {
15+
return port
16+
}
17+
18+
return false
19+
}
20+
21+
const port = normalizePort(process.env.PORT || '3000')
22+
app.set('port', port)
23+
24+
const server = http.createServer(app)
25+
26+
server.listen(port)
27+
server.on('error', onError)
28+
server.on('listening', onListening)
29+
30+
function onError(error) {
31+
if (error.syscall !== 'listen') {
32+
throw error
33+
}
34+
35+
const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port
36+
37+
switch (error.code) {
38+
case 'EACCES':
39+
console.error(bind + ' requires elevated privileges')
40+
process.exit(1)
41+
case 'EADDRINUSE':
42+
console.error(bind + ' is already in use')
43+
process.exit(1)
44+
default:
45+
throw error
46+
}
47+
}
48+
49+
function onListening() {
50+
const addr = server.address()
51+
const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port
52+
debug('Listening on ' + bind)
53+
}

model/contacts.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"id": 1,
4+
"name": "Allen Raymond",
5+
"email": "[email protected]",
6+
"phone": "(992) 914-3792"
7+
},
8+
{
9+
"id": 2,
10+
"name": "Chaim Lewis",
11+
"email": "[email protected]",
12+
"phone": "(294) 840-6685"
13+
},
14+
{
15+
"id": 3,
16+
"name": "Kennedy Lane",
17+
"email": "[email protected]",
18+
"phone": "(542) 451-7038"
19+
},
20+
{
21+
"id": 4,
22+
"name": "Wylie Pope",
23+
"email": "[email protected]",
24+
"phone": "(692) 802-2949"
25+
},
26+
{
27+
"id": 5,
28+
"name": "Cyrus Jackson",
29+
"email": "[email protected]",
30+
"phone": "(501) 472-5218"
31+
},
32+
{
33+
"id": 6,
34+
"name": "Abbot Franks",
35+
"email": "[email protected]",
36+
"phone": "(186) 568-3720"
37+
},
38+
{
39+
"id": 7,
40+
"name": "Reuben Henry",
41+
"email": "[email protected]",
42+
"phone": "(715) 598-5792"
43+
},
44+
{
45+
"id": 8,
46+
"name": "Simon Morton",
47+
"email": "[email protected]",
48+
"phone": "(233) 738-2360"
49+
},
50+
{
51+
"id": 9,
52+
"name": "Thomas Lucas",
53+
"email": "[email protected]",
54+
"phone": "(704) 398-7993"
55+
},
56+
{
57+
"id": 10,
58+
"name": "Alec Howard",
59+
"email": "[email protected]",
60+
"phone": "(748) 206-2688"
61+
}
62+
]

model/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// const fs = require('fs/promises')
2+
// const contacts = require('./contacts.json')
3+
4+
const listContacts = async () => {}
5+
6+
const getContactById = async (contactId) => {}
7+
8+
const removeContact = async (contactId) => {}
9+
10+
const addContact = async (body) => {}
11+
12+
const updateContact = async (contactId, body) => {}
13+
14+
module.exports = {
15+
listContacts,
16+
getContactById,
17+
removeContact,
18+
addContact,
19+
updateContact,
20+
}

nodemon.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ignore": ["node_modules", "model/contacts.json"]
3+
}

0 commit comments

Comments
 (0)