Search Posts

Category: express

Express server inside angular app files

I am trying to add express inside my angular app to handle the communication with my server. I searched online about how to do it, and found out how. But I didn’t understand few things. I added a new file called server.js: const express = require(‘express’); const path = require(‘path’); const http = require(‘http’); const bodyParser = require(‘body-parser’); //Get our API routes const api = require(‘./server/routes/api’); const app = express(); //Parsers for POST Data app.use(bodyParser.json()); […]

Script works but not with node.js

I am trying to get a small Angular script to work within my .html page. If I load the page as a static page in my browser, the Angular script will run correctly. If I run my node.js app which loads the same page under a res.render statement, the Angular script does not run. My theory is that my Angular code conficts with the Express.js code running. However, I’m not sure how. Here are my […]

Check that token is valid or invalid using jwt

Hey I have one small problem with token in app. I have middleware to check token in next routes and I use tokne to isLoggedIn function in angular to check logged users. But if I change token in local storage user still is logged because token still exist but is invalid. Could you help how I can response from middleware that token is valid or invalid and next check this in angular? Question: How check […]

Passport.js Redirect from express.js to angular 2 not working

I’m trying to redirect to an angular page after login where the login functions are coded in express.js.‘/api/login’, function(req, res, next) { passport.authenticate(‘local’, function(err, user, info) { if (err) { return next(err); // will generate a 500 error } if (! user) { //return res.send({ success : false, message : ‘login failed’ }); res.redirect(‘/api/login’); } //return res.send({ success : true, message : ‘login succeeded’ }); res.redirect(‘/dashboard’); })(req, res, next); }); After form submit, the […]

node, express angular routing

get request in angular: $http.get(‘/twitter’) .success(function(response) { console.log(“here is the response: “, response); }) .error(function(err) { console.log(“oh no something went wrong: “, err); }); routing in node/express: app.get(‘/twitter’, function(req,res) { console.log(“at the twitter endpoints”); res.send(“at the twitter endpoint”); }); not sure why my routing isn’t working, but I keep getting a cannot get /twitter error Source: AngularJS

angular client fails to display images from express nodejs backend using upload path

This problem of displaying images on the angular client has disturbed me for long time, even after reading many similar questions. files are uploaded successful to the upload folder and the file details are stored in the mongodb database. This is angular client. angular v1.6 after loading image data service or factory. $scope.attachImages.push({ name: attachment.originalName, filePath:attachment.upload_path }) Then the html web page has this where I use the ng-src for image upload path. <div layout […]

Nodejs How to redirect facebook/twitter crawler bot to another server-generated page?

I am building a small app and the crawlers that scrape the HTML when I share the page do not evaluate JavaScript(Makes sense). So what I’d like to do is use some kind of server-side user-agent detection to pick up whenever a social media crawler arrives, and then instead of showing it the plain AngularJS template file, redirect it to a server-generated page that will contain the desired meta tags, all filled with the correct […]

Having trouble fetching json form node.js/express server using angular, probably url routing -(newbie)

I am in the process of making a game aplication using angular and on the client side and node.js with express on the server side and have reached a stalemate in getting json from the server. This is the angularjs call, prety simple,just get the json and read a parameter: $scope.url = ‘http://localhost:8080/game/usuario’; $scope.getInfo = function(){ $http.get($scope.url).then(function(response) { $scope.mydistance =; }); }; Then, this is the return function from the server. app.get(“/game/usuario”, function(req,res){ […]

ngRoute loads only template on refresh

I have a project using nodejs with express & pug in the backend, and AngularJS with ngroute on the frontend. The way it used to work was: I enter website, it loads index.html (with angular stuff) and then /home(with content created with pug) as a view. When i choose to enter another document, angular requests it from express, and server fills it with pug (eg. /users), angular loads it into view leaving menu,etc. untouched It […]

Next Page »