express

Unnesting Node database calls

爷,独闯天下 提交于 2020-12-26 06:58:18
问题 I have an ordinary var express = require('express') Node express www page, using session, pug, etc as usual. My db calls var db = require('./scripts/myHappyMysqlScript') I'm naturally using mysql , so in the db script var mysql = require('mysql') So for example app.get('/catPhotos', (req, response) => { response.render('catPhotos.pug'); }) Say a page has a table showing something from the petNames database, app.get('/pets', function(req, res, next) { db.allPetNames(function(err, petsList) {

Unnesting Node database calls

为君一笑 提交于 2020-12-26 06:54:38
问题 I have an ordinary var express = require('express') Node express www page, using session, pug, etc as usual. My db calls var db = require('./scripts/myHappyMysqlScript') I'm naturally using mysql , so in the db script var mysql = require('mysql') So for example app.get('/catPhotos', (req, response) => { response.render('catPhotos.pug'); }) Say a page has a table showing something from the petNames database, app.get('/pets', function(req, res, next) { db.allPetNames(function(err, petsList) {

Can't get stylesheet to work with ejs for node.js

随声附和 提交于 2020-12-24 15:40:54
问题 I'm trying to make a simple server with node, express and ejs for the template. I've gotten the server to point to the page, load it, and am even able to generate other bits of code with the include statement. However for some reason the style sheet will not load. app.js var express = require('express'), app = express(), http = require('http'), server = http.createServer(app), fs = require('fs'); var PORT = 8080; app.set('view engine', 'ejs'); app.get('/', function(req, res){ res.render(

Call java program from Node.js application

只愿长相守 提交于 2020-12-22 06:57:20
问题 From what I read, there are a couple of ways to run java files in a node.js application. One way is to spawn a child process: (the java code is packaged with dependencies in an executable jar .) var exec = require('child_process').exec, child; child = exec('java -jar file.jar arg1 arg2', function (error, stdout, stderr){ console.log('stdout: ' + stdout); console.log('stderr: ' + stderr); if(error !== null){ console.log('exec error: ' + error); } }); The other way is to use the java - npm

Adding Background image to EJS file

大城市里の小女人 提交于 2020-12-16 08:05:49
问题 I seem to be fine getting an image to render from my app.js file to the main ejs file, but when i change it to a background image, it does not display. Any idea whats up? my app.js const express = require("express"), app = express(), bodyParser = require("body-parser"), jade = require("jade"), path = require('path'), redis = require('redis'); images = [{image:"http://nuvotera.com/wp-content/uploads/2013/10/email-protection-banner-2.jpg"}]; app.use(bodyParser.urlencoded({extended:true})); app

Adding Background image to EJS file

谁说我不能喝 提交于 2020-12-16 08:05:08
问题 I seem to be fine getting an image to render from my app.js file to the main ejs file, but when i change it to a background image, it does not display. Any idea whats up? my app.js const express = require("express"), app = express(), bodyParser = require("body-parser"), jade = require("jade"), path = require('path'), redis = require('redis'); images = [{image:"http://nuvotera.com/wp-content/uploads/2013/10/email-protection-banner-2.jpg"}]; app.use(bodyParser.urlencoded({extended:true})); app

Pg Promise timeout while using express generator format, but works fine with basic express sever

耗尽温柔 提交于 2020-12-16 07:03:20
问题 Pg-promise is Not returning anything for 60s and gets timed out while running server setup with express-generator. There are no error messages. All the routes without db.any or similar query, works fine. The routes with db.* times out. But, the same connection/route/query works perfectly with a simple express app. I am running this from AWS EC2. Here is the test sample express that worked fine. Same route in routes/index.js does not work - gets timed out. const express = require('express');

“message”: “ENOENT: no such file or directory, open 'E:\\astrology\\utils\\uploads\\1600798534862qf.png'”

[亡魂溺海] 提交于 2020-12-15 08:35:30
问题 As the title suggests, I am getting error: {"message": "ENOENT: no such file or directory, open 'E:\\astrology\\utils\\uploads\\1600798534862qf.png'"} in my project even after passing every required configs. Note: I've divided 'app' into two parts: main 'app.js' and 'appRoute.js' for more dynamic and code clarity. app.js const express = require("express"); const path = require("path"); const app = express(); const directory = path.join(__dirname, "utils/uploads"); app.use("/uploads", express

“message”: “ENOENT: no such file or directory, open 'E:\\astrology\\utils\\uploads\\1600798534862qf.png'”

倾然丶 夕夏残阳落幕 提交于 2020-12-15 08:35:16
问题 As the title suggests, I am getting error: {"message": "ENOENT: no such file or directory, open 'E:\\astrology\\utils\\uploads\\1600798534862qf.png'"} in my project even after passing every required configs. Note: I've divided 'app' into two parts: main 'app.js' and 'appRoute.js' for more dynamic and code clarity. app.js const express = require("express"); const path = require("path"); const app = express(); const directory = path.join(__dirname, "utils/uploads"); app.use("/uploads", express

"React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:5000 (ECONNREFUSED)'? Error.. No solution online

谁都会走 提交于 2020-12-15 06:54:53
问题 I am trying to connect my react frontend to the backend i tried everything but its still not working. I added "proxy" : "localhost:5000" and no luck. I tried const { createProxyMiddleware } = require('http-proxy-middleware'); module.exports = function (app) { app.use( '/api', createProxyMiddleware({ target: 'http://localhost:5000', changeOrigin: true, }) ); }; and also no luck. Has anyone found a solution to the problem. I looked all over stackoverflow UPDATE : Index file // Imports const