Skip to content

express

wiki.concepts.list.Boilerplate

import express from 'express';
import dotenv from 'dotenv';
let dotenv_config = dotenv.config()

var app = express();
app.use(express.urlencoded({extended: true}));
app.use(express.json()) // To parse the incoming requests with JSON payloads
// app.use(express.static("static"));


// This responds with "Hello World" on the homepage
// app.get('/', function (req, res) {
//   console.log("Got a GET request for the homepage");
//   res.send('Hello GET');
// })

// app.get("/", (req, res) => {
//     res.sendFile(path.join("./static", "public", "index.html"));
//   });

app.post('/query', async function (req, res) {
    console.log(req.body)
    try {
        // Actually do or calculate something
        console.log(req.body)
        res.send(req.body)
    } catch (err){
      res.send(err)
    }
})


var server = app.listen(8081, function () {
    var host = server.address().address
    var port = server.address().port
    console.log("Example app listening at http://%s:%s", host, port)
 })


File Upload

File Uploads with Express.js 4.0+ | by Ricky Romero | Medium

Errors