Categories
Development

How to close connection in node js mssql?

I’m using mssql npm for connecting to SQL Server. When I connect to the database and get or post data, the connection is open yet. How can I close the connection after each request? This is a kind of request I use: router.get(‘/getnotification/:userid’,async(req,resp,next)=>{ (async function(){ let pool = null; try{ pool = await connection let […]

Categories
Development

Mongoose change date based on another field

so here is my problem. I am writting an app, course app and I have hit a wall. My problem is that, whenever user adds new course to database it automatically set up two field called startingDate and nextClasses. At the beginning nextClasses field is equal to startingDate but I’d like to periodically change that […]

Categories
Development

How to call muliple method in same HTTP request in MEAN app

I need to send http requests and get response from server according precedence order. This is my admin.js file const express = require(‘express’) const router = express.Router() const User = require(‘../models/User’) const deletedUser = require(‘../models/deletedUser’) const multer = require(‘multer’) //all users router.get(‘/users’, async(req,res)=>{ try{ const user = await User.find(); res.send(user); }catch(err){ res.json({message: err}); } }); […]

Categories
API Development Heroku

503 error when trying to access API deployed on heroku

when i am trying to access the below routes(create user,login) from postman i get 503 and a html error page 2019-11-24T14:31:55.004357+00:00 heroku[router]: at=error code=H12 desc=”Request timeout” method=POST path=”/users” host=swagath-task-manager.herokuapp.com request_id=c7111ffc-4d55-46c2-9981-abb718493f50 fwd=”103.220.80.231″ dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https the below routes produce these errors.rest of the routes are working fine as in they are running authentication […]

Categories
Development

CastError: Cast to ObjectId failed for value “partdata” at path “_id” when I have two GET request use req.params

router.get(‘/:test_ID, async(req, res) => { const model = await models.testModel.findById(req.params.test_ID) let root_path = model.url let file_name = model.filename res.sendFile(file_name, { root: root_path }) }) router.get(‘/partdata/:test_ID’, async(req, res) => { const model = await models.testModel.findById(req.params.digitalmodel_id) res.send(model) }) I have two GET requests use the req.params.test_ID. The first one works well, the second one has the Cast […]

Categories
Development

How to separate the method to the route

I had this route and it worked perfectly router.get(‘/api/User/:id’,async(req,res)=>{ try { const{id}=req.params; let result =await pool1.request() .input(‘Iduser’, sql.Int, id) .execute(‘GetUser’) res.json(result); } catch (err) { res.json({ error: ‘Does Not exist’ }) } }); But I want to separate the function and leave the route as clean as possible, try to separate it as follows but […]

Categories
Development

How can I implement this model

how can I implement this [{ “title”: “pranam”, “year”: “2016”, “rating”: 9, “actors”: [ { “name”: “Amir”, “birthday”: “16 Aug 1982”, “country”: “Bangladesh” }, { “name”: “Imran”, “birthday”: “15 Aug 1982”, “country”: “Bangladesh” } ] }] I had tried this …… models/actors.js const Joi = require(‘joi’); const mongoose = require(‘mongoose’); const actorSchema = new mongoose.Schema({ […]

Categories
Angular Development

Output of different userid gets mixed when requesting same api through angular in node js

I am facing a strange situation I have one route in node js that looks something like: route.post(“/api”,async(req,res)=>{ let userid=req.body.userid; // requesting data from the db for particular userid res.json({data:data}) }) Now When I requesting this api with setInterval from my angular app export myClass implements OnInit{ data: any; GetData() { this.http.post(“/api”, { userid: userid […]

Categories
Angular Development

Output of different userid gets mixed when requesting same api through angular in node js

I am facing this strange situation I have one route in node js something like route.post(“/api”,async(req,res)=>{ let userid=req.body.userid; // requesting data from the db for particular userid res.json({data:data}) }) Now When I requesting this api with setInterval from my angular app export myClass{ data:any; GetData() { this.http.post(“/api”,{userid:userid}).subscribe(result=>{ this.data=result }); } } Now when ,I am […]