express

Schema hasn't been registered for model “categories”. Use mongoose.model(name, schema)

老子叫甜甜 提交于 2020-01-25 21:13:27
问题 When i called my function in controller through postman,it worked fine and i got results but when i wrote a test case for the same function it is saying the error as MissingSchemaError: Schema hasn't been registered for model "categories". Use mongoose.model(name, schema) I was completely confused about these because how come a function that is working well go wrong with test case.Can any one suggest help please. My test.js, var server = require('../modules/categories/model/categories.server

how to disconnect socket on session expire

邮差的信 提交于 2020-01-25 17:41:09
问题 I have a small express application this also contains the socket program. When ever user success login it creates the session and socket connection perfectly. But MY problem was when the express session expire or session delete by cookie manager, the socket still in the active connection. it receiving the messages. how to disconnect even if the session are not available after the success login. Here my code was: This is my html file which gets the alert message: <!DOCTYPE html> <html> <head>

how to disconnect socket on session expire

孤者浪人 提交于 2020-01-25 17:37:10
问题 I have a small express application this also contains the socket program. When ever user success login it creates the session and socket connection perfectly. But MY problem was when the express session expire or session delete by cookie manager, the socket still in the active connection. it receiving the messages. how to disconnect even if the session are not available after the success login. Here my code was: This is my html file which gets the alert message: <!DOCTYPE html> <html> <head>

How to show uploaded images to the sever side once again in browser using MEAN stack?

巧了我就是萌 提交于 2020-01-25 12:25:29
问题 I am using MEAN stack to write and app to upload an image, to have a preview of it, and at the same time to upload this image to server(server in Express) and savinig it in MongoDB database. On the other hand side, I need this get this image back from Mongo and Server to display in on the browser once again. Here is my wiring: Client-side: Using Farid Daniel custsom directive the HTML uploading button is <span class="btn btn-default btn-file"> <input type="file" ngf-select ngf-change=

Handling /_ah/start route NodeJs at Google App Engine

余生长醉 提交于 2020-01-25 11:25:18
问题 I am using Google App Engine Standard Environment for my NodeJs App. Things were working fine until I register a route '/*' in my express app to catch all routes after my initial routes like '/', '/login' etc. . After deploying my app on GAE I got : Error: Server Error The server encountered an error and could not complete your request. Please try again in 30 seconds. In my App Engine build logs : My app.yaml looks like: app.yaml runtime: nodejs10 env: standard service: default health_check:

Simple variable passed into EJS template is undefined

試著忘記壹切 提交于 2020-01-25 10:12:42
问题 I am learning NodeJS and have built a very simple app that renders an EJS template passing a string variable. When I try to run it however, it says the variable "greeting" is undefined: app.js: var express = require("express"); var app = express(); app.set("view engine", "ejs"); app.get('/', function(req, res) { res.render("index.ejs", { greeting: "Hello World" }); }); app.listen(3000); index.ejs: <h1>Testing out EJS</h1> <h2>Greeting is: <%= greeting %></h2> Any ideas as to why this doesn't

A http 204 response returns a blank page in iOS, is there a way to stop this?

余生颓废 提交于 2020-01-25 09:40:08
问题 This may have been asked before but I can't seem to find a solution, so apologies if this is the case. I have a simple node app in development which uses express. One of the post routes returns a http 204 and sends it, below is my code: router.post("/:id", function(req, res, next) { if (!req.session.userId) { res.status(204).send(); } else { console.log(req.params.id); User.findById(req.session.userId, function (err, user) { if (err) return handleError(err); const nameForDatabase = req.params

How to avoid multiple HttpInterceptor calls while navigating between RxJS mergeMap?

假装没事ソ 提交于 2020-01-25 09:20:08
问题 I'm using two JWT tokens - Refresh Token(expires after 7 days) and Access Token (expires after 15 min). They are stored on httpOnly cookies and can be accessed via server. Refresh methods signs new token and store it on a cookie. I need to check if these tokens are expired after every request like this: @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private authService: AuthService, private cookieService: CookieService) { } intercept(req: HttpRequest<any>,

Port “already in use” after each server restart

筅森魡賤 提交于 2020-01-25 09:19:24
问题 Searching for help with peculiar issue. Each time I stop and restart the server, I get this message: Jim@Jim-PC MINGW64 ~/nodeProjects/express-locallibrary-tutorial $ npm start > express-locallibrary-tutorial@0.0.0 start C:\Users\Jim\nodeProjects\express-locallibrary-tutorial > node ./bin/www Port 3300 is already in use npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! express-locallibrary-tutorial@0.0.0 start: `node ./bin/www` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the express

Access req and res inside of app.locals

人盡茶涼 提交于 2020-01-25 08:50:07
问题 Trying to write some helper methods for an express 3.0 app. Here is an example to greet the user: app.locals.greet = function(req,res) { return "hey there " + req.user.name; } However, req and res aren't available inside that function. How would I go about writing helpers that I can use inside my jade templates? Am I doing this wrong? 回答1: Have a look at my config app.js file! that should work to you as the variables will e available at that context. app.configure(function(){ app.set('views',