express

How to share the same variable between modules?

余生颓废 提交于 2020-01-12 07:46:01
问题 I'm using Node.JS with Express.js and I need to share a variable between modules, I have to do that because this variable is a pool of mysql connections, This pool creates 3 Mysql connections at the start of Node.js and then I would like that the other modules will use those connections without recreate other pools. Is this possible? Thanks 回答1: There are 2 options: make that variable a global one, for ex: global.MySQL_pool = ... . This way you can access it everywhere by using MySQL_pool as

Why does the zombie.js browser return empty HTML when using Bootstrap?

感情迁移 提交于 2020-01-12 04:39:09
问题 I'm trying to test my Node.js/Express.js application using Mocha and Zombie. I can get simple tests to pass, but as soon as I add the script tags for Twitter Bootstrap to my views, the browser object returns empty HTML. Here is my test code: process.env.NODE_ENV = 'test'; var app = require('../app'); var assert = require('assert'); var Browser = require('zombie'); describe('home page', function() { before(function() { this.server = app.listen(3000); this.browser = new Browser({site: 'http:/

Declare separate Firebase Cloud Functions and still use Express.js

做~自己de王妃 提交于 2020-01-12 03:40:06
问题 There are many examples of using Express for Firebase Cloud Functions. In every example of I have found the code exposes the Express app as a single Cloud Function: exports.app = functions.https.onRequest(app); For one's Firebase Project Functions that means they will see one entry called "app" and all logs for all Express.js HTTP listeners will go to one place in Firebase. This also means, no matter how large one's Express.js app is, Firebase will deploy a single function in production for

How to set up local subdomains for Node.js app

∥☆過路亽.° 提交于 2020-01-12 03:16:12
问题 I am running an express app on node.js. The app uses the express-subdomain module to help handle routes for two different subdomains (sub1.example.com and sub2.example.com). I'm hosting the app on AWS Elastic Beanstalk. In my production environment, everything works great. But on my local machine, I cannot get this to work. I tried adding the subdomains to my host file 127.0.0.1 localhost sub1.localhost sub2.localhost . Although that allows me to prepend a subdomain to localhost, the module

How to set up local subdomains for Node.js app

别说谁变了你拦得住时间么 提交于 2020-01-12 03:16:08
问题 I am running an express app on node.js. The app uses the express-subdomain module to help handle routes for two different subdomains (sub1.example.com and sub2.example.com). I'm hosting the app on AWS Elastic Beanstalk. In my production environment, everything works great. But on my local machine, I cannot get this to work. I tried adding the subdomains to my host file 127.0.0.1 localhost sub1.localhost sub2.localhost . Although that allows me to prepend a subdomain to localhost, the module

Mocha API Testing: getting 'TypeError: app.address is not a function'

僤鯓⒐⒋嵵緔 提交于 2020-01-11 15:47:33
问题 My Issue I've coded a very simple CRUD API and I've started recently coding also some tests using chai and chai-http but I'm having an issue when running my tests with $ mocha . When I run the tests I get the following error on the shell: TypeError: app.address is not a function My Code Here is a sample of one of my tests ( /tests/server-test.js ): var chai = require('chai'); var mongoose = require('mongoose'); var chaiHttp = require('chai-http'); var server = require('../server/app'); // my

How to set a variable for the main handlebars layout without passing it to every route?

允我心安 提交于 2020-01-11 15:47:13
问题 I'm using handlebars with nodejs and express. This is my main.handlebars file: <!doctype html> <html> <head> ... </head> <body> <div class ="container"> ... <footer> © {{copyrightYear}} Meadowlark Travel </footer> </div> </body> </html> So far I'm passing the copyright year to every route: var date = new Date(); var copyrightYear = date.getFullYear(); app.get( '/', function( req, res) { res.render( 'home', { copyrightYear: copyrightYear } ); } ); Is it possible to set the copyrightYear

Mocha API Testing: getting 'TypeError: app.address is not a function'

对着背影说爱祢 提交于 2020-01-11 15:47:06
问题 My Issue I've coded a very simple CRUD API and I've started recently coding also some tests using chai and chai-http but I'm having an issue when running my tests with $ mocha . When I run the tests I get the following error on the shell: TypeError: app.address is not a function My Code Here is a sample of one of my tests ( /tests/server-test.js ): var chai = require('chai'); var mongoose = require('mongoose'); var chaiHttp = require('chai-http'); var server = require('../server/app'); // my

Deep query to nested types in GraphQL return NULL

痴心易碎 提交于 2020-01-11 13:23:08
问题 Have a strange problem... Query to nested types return null. But, if I return anything in parent type - resolve return right result My code: import { GraphQLList, GraphQLString, GraphQLID, GraphQLObjectType, GraphQLSchema } from 'graphql'; import AdminModel from '../models/Admin.model'; const AdminType = new GraphQLObjectType({ name: 'AdminType', fields: { _id: { type: GraphQLID }, login: { type: GraphQLString }, password: { type: GraphQLString } } }); const AdminRooteType = new

req.body is undefined mean app

戏子无情 提交于 2020-01-11 12:39:11
问题 I have an issue on my app. The simple way to tell you whats the problem let mme show you my code var Meetup = require('./models/meetup'); module.exports.create = function (req, res) { var meetup = new Meetup(req.body); console.log(req.body); meetup.save(function (err, result) { console.log(result); res.json(result); }); } module.exports.list = function (req, res) { Meetup.find({}, function (err, results) { res.json(results); }); } console.log(req.body) ; outputs undefined console.log(result)