express

Node JS res.sendFile() not working

冷暖自知 提交于 2020-01-05 07:18:26
问题 I'm getting ReferenceError: main is not defined when I open up the http://localhost:3000/ Here I try to open up the main.html located in views directory This is my app.js const express = require('express'), app = express(), config = require('./config/index'), routes = require('./routes/route'); app.use(express.static(`${__dirname}/public`)); app.use(express.static(`${__dirname}/views`)); app.use('/',routes); app.listen(config.port,()=>{ console.log(`Listing at port ${config.port}`)}) This is

How to insert data to mongo synchronously (Nodejs, Express)

旧街凉风 提交于 2020-01-05 06:50:26
问题 I have a problem with inserting data to mongo db using node(express) My code looks like this: router.get('/data/:section/:sort', function(req, res, next) { //Deleting old data always before writing new //Image.remove().exec(); var section = req.params.section; var sort = req.params.sort; //Link to Igmur API var url = 'https://api.imgur.com/3/gallery/'+section+'/'+sort+'/1'; //1 at the end is used to get more than 60 images(gives only 60 without it) request.get({ url: url, method: 'GET',

Jade template doesn't get the data passed from express

三世轮回 提交于 2020-01-05 05:36:06
问题 I know this questions has almost the same title but the issue is different. I'm using Jade template engine v.1.11.0 built into latest Keystone.js release. In a controller, I query the data with two view.on('init') callbacks. First callback only queries one record and always passes. The second sometimes don't. category.js var keystone = require('keystone'); var async = require('async'); exports = module.exports = function (req, res) { var view = new keystone.View(req, res); var locals = res

How to save JWT Token in Vuex with Nuxt Auth Module?

不打扰是莪最后的温柔 提交于 2020-01-05 05:27:11
问题 I am currently trying to convert a VueJS page to NuxtJS with VueJS. Unfortunately I have some problems with authenticating the user and I can't find a solution in Google. I only use Nuxt for the client. The API is completely separate in express and works with the existing VueJS site. In Nuxt I send now with the Auth module a request with username and password to my express Server/Api. The Api receives the data, checks it, and finds the account in MongoDB. This works exactly as it should. Or

Sending/handling GET requests in typescript using Express, Request and Node.js

本小妞迷上赌 提交于 2020-01-05 05:25:07
问题 I'm using a combination of Express and Request (installed using npm) to try to send a get request to get some json from the server. However no matter what I do the body that is returned is "undefined". This is the code in my server.js file. The json isn't actually what I'm sending, it's just an example as I can't post what I'm actually sending. import express = require("express"); import bodyParser = require("body-parser"); let app = express(); app.use(bodyParser.json()); app.get('/config',

app.set and then TypeError: app.get is not a function

浪子不回头ぞ 提交于 2020-01-05 04:56:11
问题 While using express 4.x, I am setting the port in my server.js like in the following. var express = require('express'); var app = express(); ... var port = process.env.PORT || 8080; app.set('port', port); ... module.exports = app; But when I try to access it within my routes file, like the following... // path to routes file is app/models, hence the '../../' var app = require('../../server'); // default route router.get('/', function (req, res) { res.send('Hello! The API is at http:/

node express + formidable + form with multipart/form-data how to get req.body?

六眼飞鱼酱① 提交于 2020-01-05 04:40:06
问题 I'm using mean stack and formidable to upload file the form has a multipart/form-data attribute exports.create = function(req, res) { console.log(req.body); } but the rq.body is empty. How can I get it ? 回答1: If you are using formidable for multipart upload, you can get req.body fields in form.parse(req, function(err, fields, files) fields.item 来源: https://stackoverflow.com/questions/21238334/node-express-formidable-form-with-multipart-form-data-how-to-get-req-body

pdfmake returns blank page for 'fs.createWriteStream'

浪尽此生 提交于 2020-01-05 04:37:27
问题 using node 8.11 and pdfmake 0.1.53 and pm2 . pdfmake gives a mixed response, but almost fails(blank page) and success(with content) randomly. Is it temp storage bug? tried with a different name too but getting blank page, after close and open system getting first time proper, next onwards getting empty pages. note: the direct download does not fail always. attached the sample at last. sample code: module.exports = { generateReport: function(req, res){ var fonts = { Roboto: { normal: 'node

greenlock (lets'encrypt) with express and port forwarding

会有一股神秘感。 提交于 2020-01-05 04:37:11
问题 I am trying to set up letsencrypt (now greenlock apparently) for port forwarding with express. I had this first issue that I solved with: iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000 iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 3443 The issue is that, now, I get: Fetching certificate for 'xxx' to use as default for HTTPS server... [acme-v2] handled(?) rejection as errback: Error: connect ECONNREFUSED 127.0.1.1:80 at TCPConnectWrap

Get raw query generated by sequelize.js [duplicate]

只愿长相守 提交于 2020-01-05 04:34:10
问题 This question already has answers here : How can I see the SQL generated by Sequelize.js? (3 answers) Closed 2 years ago . Good afternoon everyone. I am developing a node.js/express system using sequelize.js (postgresql). My problem is: I need to store the raw queries generated by sequelize in a log history, but I can't find a function that returns the generated query. Does anyone know if sequelize provides a function that returns the generated SQL query, or if there's any other way to