express

[node][mocha]Global variables not accessible when testing with mocha

柔情痞子 提交于 2021-01-27 10:01:09
问题 I'm trying to create a unit test for express node application. I want the configuration used for the test to be different than the one used in production, so I implemented the following. In my index.js , I load the configuration into the global variable like this: global.env = {}; global.env.config = require('./config/config'); // Create the server ... server.listen(3000); module.exports = server; In some other controller myController.js , I access the global variable like this var Config =

Module has not default export after converting to Typescript

被刻印的时光 ゝ 提交于 2021-01-27 06:59:15
问题 I have converted the JavaScript code to Typescript and getting the error Module has no default export I have tried importing using the curly braces and exporting using module.exports but none of them worked. contactController.ts const contacts: String[] = []; // Handle index actions exports.index = (req: any, res: any) => { res.json({ data: contacts, message: "Contacts retrieved successfully", status: "success" }); }; // Handle create contact actions exports.new = (req: any, res: any) => { //

CSRF doesn't work on the first post attempt

老子叫甜甜 提交于 2021-01-27 06:27:28
问题 This is my first time implementing CSRF and first time posting on Stack. I've struggled through the CSRF config, but finally got something that almost works. If I open a bookmarked page in a fresh browser and submit a form, I'm seeing a 403 Invalid CSRF error: EBADCSRFTOKEN. In this case, the user auth is cookied so it does not challenge. I wonder if the session is expired? Subsequent posts work fine. Get requests are all fine. I'm stumped, time to put this challenge aside and ask for help as

res.clearCookie function doesn't delete cookies

百般思念 提交于 2021-01-27 05:52:55
问题 I am creating an authorization system for my express (with typescript) application and I use JWT and save them into cookies to keep the user logged in. I have a problem with the logout part and res.clearCookie() doesn't delete cookies. I have used cookie-parser in the index file and I have tried resetting the cookie with an empty value or expiration date of now but it doesn't work for me. As I stated above res.clearCookie("jwt") doesnt work either. All dependencies are up-to-date. Login and

res.clearCookie function doesn't delete cookies

三世轮回 提交于 2021-01-27 05:52:53
问题 I am creating an authorization system for my express (with typescript) application and I use JWT and save them into cookies to keep the user logged in. I have a problem with the logout part and res.clearCookie() doesn't delete cookies. I have used cookie-parser in the index file and I have tried resetting the cookie with an empty value or expiration date of now but it doesn't work for me. As I stated above res.clearCookie("jwt") doesnt work either. All dependencies are up-to-date. Login and

req.busboy.on('file') not firing

狂风中的少年 提交于 2021-01-27 05:15:26
问题 I have the following form: form(method='post', action='/encoder_post', enctype='multipart/form-data') .form-group label(for='name') Name input.form-control(type='text', id='name', name='name') .form-group label(for='message') Message input.form-control(type='text', id='message', name='message') .form-group label(for='file') Audio File (*.wav) input.form-control(type='file', id='file') button.btn.btn-cicada.btn-block(type='submit') Submit Inside encoder_post , I have the following function to

req.busboy.on('file') not firing

吃可爱长大的小学妹 提交于 2021-01-27 05:15:22
问题 I have the following form: form(method='post', action='/encoder_post', enctype='multipart/form-data') .form-group label(for='name') Name input.form-control(type='text', id='name', name='name') .form-group label(for='message') Message input.form-control(type='text', id='message', name='message') .form-group label(for='file') Audio File (*.wav) input.form-control(type='file', id='file') button.btn.btn-cicada.btn-block(type='submit') Submit Inside encoder_post , I have the following function to

Mongoose findoneandupdate returns updated document but not updated in database

ⅰ亾dé卋堺 提交于 2021-01-27 04:40:01
问题 The schema is correct, and these fields should be updating. So, I get partial data from one API call. And some from another. Which I'll note below. My schema: var coin = new Mongoose.Schema({ id: Number, rank: Number, source: String, symbol: String, name: String, cap: String, heat: Number, circulating_supply: Number, total_supply: Number, max_supply: Number, change: { hour: String, day: String }, quotes: { USD: { price: Number, volume_24h: Number, market_cap: Number, percent_change_1h: Number

Mongoose findoneandupdate returns updated document but not updated in database

人盡茶涼 提交于 2021-01-27 04:39:08
问题 The schema is correct, and these fields should be updating. So, I get partial data from one API call. And some from another. Which I'll note below. My schema: var coin = new Mongoose.Schema({ id: Number, rank: Number, source: String, symbol: String, name: String, cap: String, heat: Number, circulating_supply: Number, total_supply: Number, max_supply: Number, change: { hour: String, day: String }, quotes: { USD: { price: Number, volume_24h: Number, market_cap: Number, percent_change_1h: Number

dependency cycle detected import/no-cycle

戏子无情 提交于 2021-01-27 02:25:29
问题 I am trying to set up API endpoints in ES6. In my main server file, I tried to import the router module but I get the error "dependency cycle detected import/no-cycle". Please find my code below for clearance and assistance. import express from 'express'; import bodyParser from 'body-parser'; import router from './routes/routes'; const app = express(); const PORT = process.env.PORT || 8080; app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); // app.use(routes); app