Created
April 22, 2021 03:31
-
-
Save bbachi/efc48fdcf2801b15b2cbf579c90c3e54 to your computer and use it in GitHub Desktop.
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'); | |
var bodyParser = require('body-parser'); | |
const app = express(), | |
port = 8080; | |
const users = []; | |
app.use(bodyParser.urlencoded()); | |
app.use(bodyParser.json()); | |
app.use(express.static(process.cwd()+"/my-app/dist/angular-nodejs-example/")); | |
app.get('/api/users', (req, res) => { | |
res.json(users); | |
}); | |
app.post('/api/user', (req, res) => { | |
const user = req.body.user; | |
users.push(user); | |
res.json("user addedd"); | |
}); | |
app.get('/', (req,res) => { | |
res.sendFile(process.cwd()+"/my-app/dist/angular-nodejs-example/index.html") | |
}); | |
app.listen(port, (err) => { | |
if(err) { | |
console.log(err) | |
} | |
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