MongoError: Topology is closed, please connect despite established database connection

I’ve found the solution to the problem, but I’m not sure I understand the reasoning. The client.close() in the finally block of the validateUniqueUser function. It was closing the connection before the connection in the createPracticeProfile function was finished inserting the user. When that line is taken out, the function works.

Calling already defined routes in other routes in Express NodeJS

Similar to what Gates said, but I would keep the function(req, res){} in your routes file. So I would do something like this instead: routes.js var myModule = require(‘myModule’); app.get(“/firstService/:query”, function(req,res){ var html = myModule.firstService(req.params.query); res.end(html) }); app.get(“/secondService/:query”, function(req,res){ var data = myModule.secondService(req.params.query); res.end(data); }); And then in your module have your logic split up … Read more

Argument of type ‘NextHandleFunction’ is not assignable to parameter of type ‘PathParams’

I was able to fix the error this way: import bodyParser from ‘body-parser’; import express, { Express, RequestHandler } from ‘express’; const app: Express = express(); app.use(bodyParser.json() as RequestHandler); app.use(bodyParser.urlencoded({ extended: true }) as RequestHandler);

express.js 4 and sockets with express router

One option is to pass it in to req object. app.js: var express = require(‘express’); var path = require(‘path’); var logger = require(‘morgan’); var api = require(‘./routes/api’); var app = express(); var io = require(‘socket.io’).listen(app.listen(3000)); app.use(logger(‘dev’)); app.use(express.static(path.join(__dirname, ‘public’))); io.sockets.on(‘connection’, function (socket) { console.log(‘client connect’); socket.on(‘echo’, function (data) { io.sockets.emit(‘message’, data); }); }); // Make io … Read more

How to make an Express site without a template engine?

If what you want is directly to serve static html files with the possibility to cache resources, while still being able to hit “https://stackoverflow.com/” and get index.html, then the answer is as easy as this: var express = require(‘express’); var http = require(‘http’); var app = express(); app.use(express.static(__dirname + ‘/public’)); http.createServer(app).listen(3000); Gotcha: Html files including … Read more

node.js express createServer() not a function

Change: var express = require(‘express’); var app = module.exports = express.createServer(); To: var express = require(‘express’); var app = express(); //Middleware app.listen(3000) You can also globally install express with the following command and then automatically generate a express template with the following command: npm install -g express Generate template: express myAppName cd . && npm … Read more

Concatenating a variable + string in Jade file

use #{} notation if you want to interpolate a variable in the contents of an element. you can just use the variable names straight up if you want to use them in attributes. link(rel=”stylesheet”, href=”https://stackoverflow.com/stylesheets/” + pref + ‘.css’) equivalent: link(rel=”stylesheet”, href=”https://stackoverflow.com/stylesheets/” + locals.pref + ‘.css’) when to use #{}: a(href=”https://stackoverflow.com/stylesheets/” + locals.pref + ‘.css’) … Read more