ReferenceError: require is not defined wbepack code example
Example 1: require is not defined
remove "type": "module" from package.json
Example 2: ReferenceError: require is not defined site:stackoverflow.com
const cors = require('cors');
const express = require('express');
const bodyParser = require('body-parser');
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Am I really running a server?!');
}).listen(8080, '127.0.0.1');
console.log('running server!');
const port = 8080;
projectData = {};
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors());
app.use(express.static('website'));
app.listen(port, () => {
console.log(`server working on : http://localhost:${port}...`)
});
app.get('/all', (req, res) => {
res.send(projectData).status(200).end();
});
app.post('postAll', (req, res) => {
projectData = {
temp: req.body.temp,
date: req.body.date,
content: req.body.content
};
res.send(projectData).status(200).end();
});