У меня проблемы с запуском простого сервера Node.js Express.js на локальном хосте.
Я пытался с
узлом Express.js
безрезультатно.
Я получил эту ошибку
$ node Express.js
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EACCES 127.0.0.1
at Object._errnoException (util.js:992:11)
Мой код
// express.js
const mysql = require('mysql');
const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');
const hostname = '127.0.0.1';
const port = '8080';
const app = express();
app.set('port', process.env.PORT || 8080);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const con = mysql.createConnection({
host: 'localhost',
user: 'bojan',
password: 'Hamurabi77',
database: 'user'
});
con.connect((err) => {
if (err) throw err;
console.log('Connected!');
});
const createDatabase = 'CREATE DATABASE user';
con.query(createDatabase, (err, result, fields) => {
if (err) throw err;
console.log('Created!');
});
const createTable = 'CREATE TABLE user (id AUTO_INCREMENT PRIMARY_KEY something VARCHAR(255))';
con.query(createTable, (err, result, fields) => {
if (err) throw err;
console.log('Created!');
});
app.get('/users', (req, res, end) => {
const selectUsers = `SELECT * FROM user`;
con.query(selectUsers, (err, result, fields) => {
if (err) throw err;
console.log('Selected!');
});
res.json();
res.send('Selected!');
res.end();
});
app.get('/users/:id', (req, res, end) => {
const selectUserByID = `SELECT * FROM user WHERE id=${req.id}`;
con.query(selectUserByID, (err, result, fields) => {
if (err) throw err;
console.log('Selected by ID!');
});
res.json();
res.send('Selected by ID!');
res.end();
});
app.post('/user/insert', (req, res, end) => {
const insertUser = `INSERT INTO user SET (something) VALUES (${req.something})`;
con.query(insertUser, (err, result, fields) => {
if (err) throw err;
console.log('Inserted!');
});
res.json();
res.send('Inserted!');
res.end();
});
app.post('/user/update/:id', (req, res, end) => {
const updateUserByID = `UPDATE user SET (something) VALUES (${req.something}) WHERE id=${req.id}`;
con.query(updateUserByID, (err, result, fields) => {
if (err) throw err;
console.log('Updated!');
});
res.json();
res.send('Updated!');
res.end();
});
app.post('/user/delete/:id', (req, res, end) => {
const deleteUserByID = `DELETE * FROM user WHERE id=${req.id}`;
con.query(deleteUserByID, (err, result, fields) => {
if (err) throw err;
console.log('Deleted!');
});
res.json();
res.send('Deleted!');
res.end();
});
router(app);
app.listen(hostname, port, () => {
console.log(`Connection running at https://${hostname}:${port}!`);
});
Что не так с моим кодом?Любые предложения будут оценены.Я ожидаю, что это будет доступно в https://localhost:8080