Skip to content

Instantly share code, notes, and snippets.

@thaerlabs
Last active November 7, 2017 19:42
Show Gist options
  • Save thaerlabs/95e02aba6d2315dcfda2304ef03d8edb to your computer and use it in GitHub Desktop.
Save thaerlabs/95e02aba6d2315dcfda2304ef03d8edb to your computer and use it in GitHub Desktop.
express sample
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const PORT = 3000;
app.use(bodyParser.json());
app.get('/', (req, res) => {
const name = req.query;
res.send('Login form');
});
app.post('/register', (req, res) => {
const body = req.body;
// get the data, validate and save the user in the database
res.send(body);
});
app.post('/login', (req, res) => {
const body = req.body;
// get the data, validate and uathneticate the user, return the toker
res.send({
token: 'fake token'
});
});
app.get('/private', (req, res) => {
// if not authenticated redirect to login
// else show something
});
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment