Skip to content

Instantly share code, notes, and snippets.

@bbachi
Created April 22, 2021 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbachi/efc48fdcf2801b15b2cbf579c90c3e54 to your computer and use it in GitHub Desktop.
Save bbachi/efc48fdcf2801b15b2cbf579c90c3e54 to your computer and use it in GitHub Desktop.
NodeJS
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