Created
June 19, 2020 20:16
-
-
Save bbachi/da0c89313bb3ed7f805036be7b69fb94 to your computer and use it in GitHub Desktop.
react nodejs
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
const express = require('express'); | |
const path = require('path'); | |
const app = express(), | |
bodyParser = require("body-parser"); | |
port = 3080; | |
// place holder for the data | |
const users = []; | |
app.use(bodyParser.json()); | |
app.use(express.static(path.join(__dirname, '../my-app/build'))); | |
app.get('/api/users', (req, res) => { | |
console.log('api/users called!') | |
res.json(users); | |
}); | |
app.post('/api/user', (req, res) => { | |
const user = req.body.user; | |
console.log('Adding user:::::', user); | |
users.push(user); | |
res.json("user addedd"); | |
}); | |
app.get('/', (req,res) => { | |
res.sendFile(path.join(__dirname, '../my-app/build/index.html')); | |
}); | |
app.listen(port, () => { | |
console.log(`Server listening on the port::${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment