Hello. I want to ask a question about the server on node.js , namely sending files to it and processing. One tutorial video, we simply created a server, and already from another author I looked at how to receive data and got confused and maybe I did something wrong. So here is my server code:

 const http = require('http'); //Обработчик формы const app = require('express')(), bodyParser = require('body-parser'); app.use('/place', bodyParser.urlencoded({ extended: false, })); app.post('/place', function(req, res, next) { console.log(req.body); }); app.listen(4000); const public = require('./resources/js/public'); const home = require('./resources/js/home'); const notFound = require('./resources/js/notFound'); http.createServer((req, res) => { if (req.url.match(/\.(html|css|js|png)$/)) { public(req, res); } else if (req.url === '/') { home(req, res); } else { notFound(req, res); } }).listen(3000, () => console.log('server working')) 

I would like to ask if we need to create some file as an indication of its path in the action and on the server in the use post ? in my case /place . What format should it be? What does app.listen mean? and maybe I made a mistake that created listen and here and below on:

 http.createServer((req, res) => { if (req.url.match(/\.(html|css|js|png)$/)) { public(req, res); } else if (req.url === '/') { home(req, res); } else { notFound(req, res); } }).listen(3000, () => console.log('server working')) 

1 answer 1

 const express = require("express"); const path = require('path'); const app = express(); app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use('/resources', express.static(path.resolve(__dirname + '/resources'))); app.post('/place', function(req, res, next) { console.log(req.body); }); const port = process.env.PORT || 3000; app.listen(port, () => console.log(`Listening on: ${port}`));