Хочу запустить бота на локальном сервере при запуске бота выдает Server running at
http://undefined:undefined/ в консоли как исправить ?
hello.js
const fs = require('fs');
const http = require('http');
const path = require('path');
const { APP_PORT, APP_IP } = process.env;
const indexPath = path.join(__dirname, 'index.html');
const server = http.createServer((req, res) => {
fs.readFile(indexPath, (err, data) => {
if (err) {
res.writeHead(400, {'Content-Type': 'text/plain'});
res.write('index.html not found');
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
}
res.end();
});
}).listen(APP_PORT, APP_IP, () => {
console.log(`Server running at http://${APP_IP}:${APP_PORT}/`);
});
process.on('SIGTERM', () => {
console.info('SIGTERM signal received.');
console.log('Closing http server.');
server.close(() => {
console.log('Http server closed.');
process.exit(0);
});
});
package.json
{
"name": "my-node-app",
"version": "1.0.0",
"description": "My Node.js App",
"main": "hello.js",
"scripts": {
"start": "node hello.js"
},
"author": "Ваше имя",
"license": "MIT",
"dependencies": {
"dotenv": "^16.3.1",
"fs": "^0.0.1-security",
"http": "^0.0.1-security",
"path": "^0.12.7"
}
}
.env
APP_PORT=3000
APP_IP=127.0.0.1