Categories
Mastering Development

Get user data with Angular httpClient

I want to fetch user data, but I always get null. Here’s my route: router.get(‘/user’, (req,res)=>{ res.send(req.user); }) Don’t want to go into the details, but on http://localhost:4000/auth/user, I have my user data, when I am logged in. Here’s my web service("framework" to all services) get part : constructor(private http:HttpClient) { } get(uri:string) { return […]

Categories
Mastering Development

How to fix error arising from passport authentication

I have been trying to figure out why I keep having the error localhost didn’t send any data displayed on the browser whenever I try to login using a registered username and password. The register section of the program is working as expected. Whenever I login using the wrong username and password, I get redirected […]

Categories
Mastering Development

Post request wont display response

Im sending a login post request to my back-end (the back end works i tested it). Seems like the method is waiting for the response and never gets it. Here is my code in vue.js. async loginUser({commit},{username,password}){ let response=await Api().post(‘/login’,{username:username,password:password}); alert(response); let user=response; commit(‘SET_CURRENT_USER’,user); A simmilar method where i just fetch data the same way […]

Categories
Mastering Development

Node.js and Express: Adding multiple flash messages

I am in a situation where there is a flash message when a file upload operation has commenced. req.flash(‘message’, ‘File Uploading!’); res.locals.messages = req.flash(); This code is on app.post(‘/’) This is what i use to catch the message: <% if (locals.messages) { %> <script language="javascript"> alert("<%= messages.message%>"); </script> <% } %> After the file gets […]

Categories
Mastering Development

Upload files with multer/Angular

Error: Multipart: Boundary not found I want to add file with some text files with angular: here’s my service: src/app/services/web.service.ts import { Injectable } from ‘@angular/core’; import { HttpClient, HttpHeaders } from ‘@angular/common/http’; const httpOptions = { headers: new HttpHeaders({ ‘Content-Type’: ‘multipart/form-data’ }) } @Injectable({ providedIn: ‘root’ }) export class WebService { devUri:string = ‘http://localhost:4000’; […]

Categories
Mastering Development

How can I fix error code : ENOENT in node js?

When I make a post request to node server with /new route it throws an error code : ENOENT . This is the appjs file : const express = require(‘express’); const app = express(); const mongoose = require(‘mongoose’); const bodyParser = require(‘body-parser’); const cors = require(‘cors’); const port = process.env.PORT || 5000; const fs = […]

Categories
Mastering Development

How to update new entry of data from node.js with the existing array of database created from a file earlier?

I am completely new to Node.js & mongo here, so this is a naive question I guess. I already have a file called students.js with three entries of students’ data. var students = [ { id: 1, name: ‘Sean Gray’, age: 24, }, { id: 2, name: ‘John Doe’, age: 26, }, { id: 3, […]

Categories
Mastering Development

How to variable from another module.exports file permanently

I’m trying to create an API call to change a variable (in this case, a password) in another file (config.js) and I want to change the value of "mainpassword" permanently (or at least until i want to change it again), without having to do complicated fs.readFile and write bullshit. Setting config.mainpassword = "somethingelse" does not […]

Categories
Mastering Development

How to rectify syntax error that of an express server code?

I am newbie learning express. This code below is throwing a syntax error that I cannot seem to rectify. The error specifically is as follows: node staticapi.js /Users/v/Desktop/CS-Extra/EIP/A5/staticapi.js:123 res.status(200).send(“Api is running”) SyntaxError: Invalid or unexpected token at wrapSafe (internal/modules/cjs/loader.js:1152:16) at Module._compile (internal/modules/cjs/loader.js:1200:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10) at Module.load (internal/modules/cjs/loader.js:1085:32) at Function.Module._load (internal/modules/cjs/loader.js:950:14) at Function.executeUserEntryPoint [as runMain] […]

Categories
Mastering Development

CORS problem with Passport.js implemented in Azure Function in Static Web App. Passport returns 401

I am working on a project which uses the Azure Static Web App offering. I have implemented a Passport.js authentication strategy powered by azure-function-express which receives a JWT in an Authentication header, validates the JWT, and returns user information. My system works locally, but returns a 401 unauthorized in deployment. When tested in deployment, Application […]