Tell us what’s happening:
i dont understand mongodb is giving an error of permission denied for
Your code so far
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const app = express();
const { MongoClient } = require('mongodb');
const client = new MongoClient(process.env.PORT)
const db = client.db("urlshortner")
const urls = db.collection("urls")
// Basic Configuration
const port = process.env.PORT || 3000
app.listen(port, () => {
console.log(`server running on port ${port}`)
});
app.use(cors());
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use('/public', express.static(`${process.cwd()}/public`));
app.get('/', function(req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
// Your first API endpoint
app.post('/api/shorturl', function(req, res) {
console.log(req.body)
res.json({ greeting: 'hello API' });
});
app.listen(port, function() {
console.log(`Listening on port ${port}`);
});
and here is my error:
> shorturl@0.0.3 start
> node index.js
node:events:497
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied mongodb+srv://moshe_david_27:@cluster0.b6hdqpq.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
at Server.setupListenHandle [as _listen2] (node:net:1881:21)
at listenInCluster (node:net:1946:12)
at Server.listen (node:net:2061:5)
at Function.listen (/workspace/boilerplate-project-urlshortener/node_modules/express/lib/application.js:635:24)
at Object.<anonymous> (/workspace/boilerplate-project-urlshortener/index.js:13:5)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1925:8)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: 'mongodb+srv://moshe_david_27:@cluster0.b6hdqpq.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0',
port: -1
}
please help me solve this problem…
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Challenge Information:
Back End Development and APIs Projects - URL Shortener Microservice