Я создаю сервер узла.Я объявил серверный класс и в конструкторе я вызываю listen в приложении Express.Затем я экспортирую этот класс сервера.
const instance = new Server ();^ TypeError: Сервер не является конструктором
index.js
const Server = require("./server");
const instance = new Server();
exports.default = instance.server;
server.js
const App = require("./app");
class Server {
constructor() {
this.app = new App();
this.instance = this.app.instance;
this.config = this.app.config;
this.server = this.instance.listen(this.config.port, "0.0.0.0");
console.log("Server Running On: 0.0.0.0:" + this.config.port);
}
}
exports.default = Server;
webpack
const path = require("path");
const WebpackShellPlugin = require("webpack-shell-plugin");
module.exports = {
mode: "development",
entry: "./src/index.js",
target: "node",
devtool: "source-map",
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.js",
sourceMapFilename: "index.js.map"
},
module: {
rules: [
{
enforce: "pre",
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
}
],
},
"plugins": [
new WebpackShellPlugin({ onBuildEnd: ["nodemon dist/index.js"] }),
]
};
npm
** "serve": "webpack --watch",