Categories
Mastering Development

Retrieve URL Parameters

I’m creating an app where each list will have multiple tasks. The URL for creating a new task would be like /lists/:listId/tasks In my app.js I’m doing this to redirect that URL to a specific route file called tasks.js: app.use(‘/lists/:listId/tasks’, tasks); Then in my tasks.js I’m doing the following: router.post(‘/’, (req, res) => { console.log(req.params.listId) […]

Categories
Mastering Development

EACCES: permission denied, open ‘/usr/local/lib/node_modules/npm/bin/npm-cli.js’

Hello sir i am new to docker, i am using ubuntu budgie(linux) 20.04 my docker version is Docker version 18.09.9, build 1752eb3 i have install docker using snap package manager and the path is like this /snap/bin/docker.machine /snap/bin/docker.compose /snap/bin/docker /snap/bin/docker.help I have install nodejs and npm in my host machine form this link nodejs install […]

Categories
Mastering Development

How can send readonly value from a form?

<form action=”/upload” method=”POST” enctype=”multipart/form-data”> <fieldset> <span>Event name</span> <input name = “name” type=”text” class=”form-control” value=”<%= `${event.name}` %>” readonly> </fieldset> <fieldset> <button type=”submit” id=”form-submit” class=”btn”>Add Event</button> </fieldset> </form> and then i’m doing req.body.name and getting undefined… How do i resolve it? app.post(“/upload”, (req, res) => { console.log(req.body.name); });

Categories
Mastering Development

Getting inconsistent API response from Firebase function

I’ve wrote an API with Firebase functions. When I’m testing locally firebase serve –only functions, giving a URL as: http://localhost:5000/techsupper-server/us-central1/app and firebase serve –only function,hosting giving the URL: http://localhost:5000 I get the responses that I’m expecting, but when I deploy my code (firebase deploy) some routes stop working. After deploying once again without changing my […]

Categories
Mastering Development

Updating fields in array -NodeJs

I have this code that loop through all users in DB then look for specific events based on the id value and if there is a match it should update the field caption with a new given data, for the code : 1- search all potential user = OK 2 – search and find events […]

Categories
Mastering Development

How do i add json data to mysql database in node.js

I am to get the json data from http://jsonplaceholder.typicode.com/users I want to populate the mysql database with the id,name,username and email from the json data. I am using a node module called ‘request’ to read the online json api const db = mysql.createConnection({ host: ‘localhost’, user: ‘root’, password: ”, database: ‘nodemysql’ }); connect db.connect((err) => […]

Categories
Mastering Development

PUT API request returning JSON body error

Im trying to update a distribution list by sending a put request, when I run this code and test it in postman by giving it a JSON body I get this error in my node.js terminal stating SyntaxError: Unexpected end of JSON input … any idea what I should change? My PUT API request app.put(“/api/Dls/Add/:groupId” […]

Categories
Mastering Development

TypeError: upload.single is not a function

I have used multer to upload files in node.js, but when i was setting up my server i got this error. TypeError: upload.single is not a function This is my server.js const express=require(‘express’); const cors=require(‘cors’); const mongoose=require(‘mongoose’); const path = require(‘path’); const router = require(‘express’).Router(); const multer = require(‘multer’); const upload = multer({dest:’images/’}); require(‘dotenv’).config(); const […]

Categories
Mastering Development

Node js push is not working, when adding a cart in case of existing user

I am pushing a product to the cart. If the user exists then I want to push the product object to the array. But it is not working. Cart Router router.post(‘/cart’, checkJwt, (req, res, next) => { const product_id = req.query.productId; const quantity = req.query.quantity; const user = req.user.id; Cart.find({ user: req.user.id}, (err, existUser) => […]

Categories
Database Development

Explaining recurring crash in postgresql deployment

I’m having trouble with unexpected system crashes emanating from a postgresql deployment on a moderately busy production server (Django 1.8 app deployed on DO droplet with a gunicorn application server and nginx reverse proxy). I’m an accidental DBA and need an expert’s opinion on piecing together what’s going on. I have no clue right now; […]