express

Node.js server overwritten entire DOM with React.JS

只谈情不闲聊 提交于 2020-01-06 17:58:37
问题 What I am trying to do: I am trying to practice MERN structure, so I wanted to set up a node.js server and react front-end first. However, what happened is that when the server gets fired, the entire DOM got overwrite, why is that? server.js is a simple node.js const express = require('express'); const app = express(); // console.log that your server is up and running app.listen(3000, () => console.log(`Listening on port 3000`)); // create a GET route app.get('/test', (req, res) => { res.send

MEANJS Get URL Parameters

☆樱花仙子☆ 提交于 2020-01-06 17:27:27
问题 I'm running my app on localhost:3000/#!/, and trying to get URL parameters for use with Express, with no luck. I've created a new server routing file that contains the following: admin.server.routes.js 'use strict'; module.exports = function(app) { // Admin Routes var admin = require('../../app/controllers/admin.server.controller'); // Both of these routes work fine. app.route('/admin/test'). get(admin.populate). put(admin.update); // First attempt, didn't work. app.route('/admin/test').get

Node.js Express - prevent access to certain URLs

依然范特西╮ 提交于 2020-01-06 17:26:51
问题 I want to prevent access to someone not logged-in to any url that starts with '/users' Here's my current code: app.use('/^users*',function (req, res, next) { if (checkAuth(req)) { console.log('authorization OK'); next(); } else { console.log('authorization failed'); res.redirect('/login'); } }); function checkAuth(req) { console.log('req',req.url); if (!req.session.user_id && req.url !== '/login' && req.url !== '/') { return false; } return true; }; but the regular expression I have is not

checking if busboy finish event has already occured or not

拈花ヽ惹草 提交于 2020-01-06 16:29:42
问题 I have a form in which I am expected to do some file processing which takes some time, so I want that finish event executes only after the processing is complete, right now node is processing the file and while it is processing the file and executes commands node if finds finish event it fires it. so, how do i make sure that the finish event is fired only after processing of all files. busboy.on('file', function(fieldname, file, filename,transferEncoding,mimeType) { var fName = uuid.v4(); var

redis:- session key not updating

喜欢而已 提交于 2020-01-06 15:12:57
问题 redisClient.set('sessionKey', userSession, function(err){ console.log(err || 'sessionKey updated'); }); The above works. But following does not update the existing session key. redisClient.get(sessionKey, function(err, userSession){ // works fine userSession = // some modification; redisClient.set(sessionKey, userSession, function(err){ console.log(err || 'sessionKey updated'); }); }); I'm using localhost with redistogo thru heroku. There is no error. Even the console.log(err || 'sessionkey

Attempting MQTT connection…failed, rc=-2 try again in 5 seconds

自古美人都是妖i 提交于 2020-01-06 14:31:56
问题 I am trying to establish MQTT communication with my local MQTT server on my pc (node.js, express, Mosca) and Esp8266. esp8286 is not connecting with my server, the error is Attempting MQTT connection...failed, rc=-2 try again in 5 seconds Can't connect to Broker. Here is Node js code: var moscaSettings = { host: '0.0.0.0', port: 1883, http: { port: 8002, host: '0.0.0.0', static: './mqtt/', bundle: true, }, }; var server = new mosca.Server(moscaSettings); // var server = new mosca.Server({ //

Attempting MQTT connection…failed, rc=-2 try again in 5 seconds

核能气质少年 提交于 2020-01-06 14:29:08
问题 I am trying to establish MQTT communication with my local MQTT server on my pc (node.js, express, Mosca) and Esp8266. esp8286 is not connecting with my server, the error is Attempting MQTT connection...failed, rc=-2 try again in 5 seconds Can't connect to Broker. Here is Node js code: var moscaSettings = { host: '0.0.0.0', port: 1883, http: { port: 8002, host: '0.0.0.0', static: './mqtt/', bundle: true, }, }; var server = new mosca.Server(moscaSettings); // var server = new mosca.Server({ //

Passport (local) is hanging on Authentication

若如初见. 提交于 2020-01-06 13:29:16
问题 I have passport local strategy set up as the following, either of the failure cases work fine. However in the case where I authenticate the server logs "d1" and then hangs, with the request remaining in a "pending" state: passport.use( new LocalStrategy({ usernameField: 'email', passwordField: 'password' }, function(email, password, done) { User.getUser(email, password).then(function(users){ if(users && users.length == 1) { console.log('d1') return done(null,users[0]) ; } else { console.log(

How to join data from two collections in MongoDB?

≡放荡痞女 提交于 2020-01-06 13:02:48
问题 I'am developing some application on MEAN.js boilerplate and I've got one problem which I'm not able to solve by myself :( I've got a following database scheme: var UserSchema = new Schema({ profession: { type: Schema.ObjectId, ref: 'Profession' }, game: { type: Schema.ObjectId, ref: 'Game' } }; var ProfessionSchema = new Schema({ assignedTaskCategories: [{ type: Schema.ObjectId, ref: 'TaskCategory' }] }); var TaskCategorySchema = new Schema({ professions: [{ type: Schema.ObjectId, ref:

.NET LINQ Expression<Func<T, bool>> Performance Issues

我与影子孤独终老i 提交于 2020-01-06 12:51:13
问题 I have two functions as follow - public IQueryable<RequestSummaryDTO> GetProgramOfficerUSA(Guid officerId) { List<string> officerCountries = UnityProvider.Instance.Get<IProgramOfficerService>().GetPOCountries(officerId).Select(c => c.CNTR_ID.ToUpper()).ToList(); Expression<Func<TaskRequest, bool>> countriesFilter = (a) => officerCountries.Contains(a.tblTaskDetail.FirstOrDefault().tblOrganization.ORG_Country.ToUpper()); Expression<Func<TaskRequest, bool>> USAAndNotDelegated = LinqUtils.And