Questions tagged [express]

20894 questions
1

votes
3

answer
202

Views

How to load asynchronous database url and initiate database connection before express.js app starts?

I have configured the express.js app to run on AWS lambda. The database URL is stored and encrypted in the Amazon KMS service so if I want to use the URL then I have to decrypt the key using AWS KMS service. // imports import mongoose from 'mongoose'; import serverless from 'serverless-http'; // KMS...
sym
1

votes
1

answer
4.5k

Views

How to download an excel (xlsx) file using Angular 5 HttpClient get method with Node/Express backend?

I have an excel file in a directory on my nodejs server - Path to the file is - ./api/uploads/appsecuritydesign/output/appsecdesign.xlsx On click of a button in my Angular 5 component I am just trying to download the file using FileSaver. Below is my Angular component. Here the template code for th...
Aakash
1

votes
1

answer
811

Views

Can't connect to mongo docker image with mongoose

I'm trying to run a simple docker setup with node and mongo: Dockerfile: FROM node:8.9.4-alpine RUN mkdir /app WORKDIR /app COPY package.json /app/ COPY package-lock.json /app/ RUN npm install ADD . /app/ docker-compose.yml: version: '3' services: db: image: 'mongo' ports: - '27017:27017' api: build...
Philip Feldmann
1

votes
2

answer
2.2k

Views

CORS 'Allow-Credentials' Nodejs/Express

My project is running on Node with an Express backend. I'm trying to query my Arango database clientside with Arangojs. ArangoDB is running on Docker on Digital Ocean. I have no issues querying my database serverside, however I get the following error on page load: Failed to load http://0.0.0.0:8529...
jayf93
0

votes
0

answer
4

Views

How to change property of newly created collection on click

I am creating a new collection from current schema with same properties. I am using nodemailer to verify email by setting a schema key to value true upon clicking the link. It is happening successfully if changing value of current schema from this code:- router.get('/verify',function(req,res){ con...
NoobCoder
1

votes
1

answer
29

Views

whats the difference between export.create and router.post?

I've seen 2 ways of creating a restful API. 1: 'export.create' and once you add code on postman you have to add it in json format. 2: 'router.post' which I understand that's using express and when you add code on postman you add it using 'x-www-form-urlencoded' What's the difference? router.post('...
LaCarl
1

votes
1

answer
784

Views

Error: A partials dir must be a string or config object in handlebars

I am sending templated email using nodemailer with nodemailer-express-handlebars, but whenever I am trying to send a mail, I am getting the Error: A partials dir must be a string or config object. I don't know what is the problem. const express = require('express'); const hbs = require('nodemailer-...
Rahul
1

votes
2

answer
28

Views

Using node.js 'util' to promisify is returning an error

I'm trying to create a function in a file to return a promis, which I will call form another file. I'm trying to use the 'util.promisify' to wrap the function, but I'm getting an error. Here is the code and the error: from my 'checkEmail.js': const Profile = require('../../models/profile'); const ut...
cnak2
1

votes
2

answer
44

Views

Cannot Get/ in node.js

I am following this http://www.expertphp.in/article/user-login-and-registration-using-nodejs-and-mysql-with-example link I get a cannot GET/ error and I have tried all the stackoverflow answers but it isn't getting solved. var express=require('express'); var bodyParser=require('body-parser'); var a...
VISHAL ISRANI
1

votes
2

answer
35

Views

href attribute in stylesheet link does not work in node

I tried running my website 2 methods. 1) By using node 2) Without using node(just index.html on my computer) However, the outcomes are different in terms of linking stylesheet. Without node, the stylesheet in style tag could be linked as usual. However, when using node as a server, the stylesheet c...
1

votes
2

answer
27

Views

Correct way to figure out what rejection a promise had?

I have an API / express router: router.post('/signup', async function (req, res) { try { var user = await controllers.user.register(req.body.username, req.body.password); req.session.user = user; res.json(user); } catch (e) { res.status(500).json('DB Error'); } }); Currently, on error, it returns 50...
user2719875
1

votes
1

answer
37

Views

Angular front-end not updating instantly

I am using Angular as front-end and express as server. I am passing new object from front-end (Angular) to server (express) via http. angular file: this.issuesService.addIssue(newIssue).subscribe(); //after adding that navigating to issues link where it displays all the issues this.router.navigate([...
Logesh S
0

votes
1

answer
27

Views

Set System Icon as Project Icon

I want to set the project icon (the one that goes in the manifest and represents the EXE compiled as it's icon) from the Shell32.dll icon library. I found this article on StackOverflow about 'How can I use the images within shell32.dll in my C# project?' but it only shows how to load the icon as a F...
SammuelMiranda
1

votes
2

answer
15

Views

Optimize Custom module code in node express

Please give me suggestion on how I can optimize my code that is present in custom module. Below is my module code that you can see and suggest. var employee = { all: function (req, res) { jwt.verify(req.token, 'novaturesol', (err) => { if (err) { res.status(400).send('Forbidden or tokken is expired!...
Peter
0

votes
1

answer
14

Views

I'm trying to run an Express static middleware from this book, and I cannot see what the example is trying to show

I'm on a section in this book about Express where it mentions express.static to serve files, but each time I run it, I get the code catching when no file is found. I have made a folder called public and put in an HTML file, and had it both in the project folder and above it but nothing happens other...
user11039951
11

votes
3

answer
3.7k

Views

create-react-app + nodejs (express) server

I am using NodeJs + React in my application. I am using express in NodeJs. I created my sample app using 'create-react-app' npm. I used NodeJs for calling the oauth token from react app. I mentioned this approach in this post Calling a secured REST api from Javascript without user login screen . I...
Michael Sync
0

votes
1

answer
106

Views

'myTable' is not associated to Model

I'm working on an express sequelize project. I've got an issue with sequelize. I've got a simply schema like the documentation says: class Task extends Model {} Task.init({ title: Sequelize.STRING }, { sequelize, modelName: 'task' }); class User extends Model {} User.init({ username: Sequelize.STRIN...
Pimento Web
1

votes
0

answer
11

Views

Node.js - How to send sessionID to GET method in Express via request package?

I'm trying to login to my Node.js (Express) app with another Node.js created script to try create a virtual bot on my app. First, i sent a POST via 'request' package to my /api/user/login and then i tried to get data from /api/user/session where i must be logged. Request script: request.post({ url:...
Hellbyte
1

votes
0

answer
8

Views

Redirect request to node application running in different Ports based on subdomains in a linux server

I have two application running in CentOS on Ports 3000 and 4000. We have configured in F5 load-balancer to redirect any request that is coming to *.test.example.com to the application running in port 3000. Later we had to change the API endpoint pointed by Node App to be changed to different API se...
pri05
0

votes
2

answer
20

Views

Regex to match URL - number at end of string, but also match characters at start of string

I need to match the following URL format /yc/leroy-jenkins-123 So I need to match both the /yc/ part and the 123 I am able to match the URL when its /leroy-jenkins-123 with the following server.get(/([^-]*)$/, (req, res) => { const actualPage = '/profile' const queryParams = { id: req.params[0] } ap...
Franco
-1

votes
0

answer
24

Views

How to use _lodash within nodejs api service

I'm trying to use the _lodash.groupBy service within a nodejs api service. I built my api following this tutorial: nodejs-mongodb-api. I then made my own API for rosters. I am trying to use _lodash to group some data before I send it back to the front end, but I'm getting an UnhandledPromiseRejectio...
DasPete
0

votes
0

answer
4

Views

Make SQLite errors specific and not just SQLITE_ERROR in express/node.js

So basically I have a similar block written in Express: var sqlite3 = require('sqlite3'); const data = {}; const db = new sqlite3.Database('sqlite/test.db'); db.run('INSERT INTO [Employees]([Name]) VALUES(?)', [name], function (err) { if (err) { //this is the error block data.err...
Abana Clara
1

votes
1

answer
3.4k

Views

send multiple responses to client via nodejs

i am using nodejs and i want to send back multiple responses to client.And my code is below //addwork var agenda = require('../../schedules/job-schedule.js')(config.db); exports.addwork = function(req, res) { var work = new Work(req.body); work.user = req.user._id; var user=req.user; work.save(funct...
sruthi karan
0

votes
0

answer
3

Views

Node: How Can I Import Web3 To Node.js?

I'm trying to import the web3 library in Node.js so that I can handle Ethereum smart contract events, however I can't get the import to work. I'm running Babel on each file to convert to es5, and the import in Node's index.js file looks like this: import Web3 from web3; When I add that 'import Web3...
Steve
1

votes
2

answer
351

Views

gzip response for a single route

I ma using express and compression library: var compression = require('compression') var express = require('express') var app = express() // compress all requests app.use(compression()) Question: How can I just add a gzip response for a single route? If may server is IIS 8 which is host at Azure web...
Alvin
1

votes
2

answer
1.5k

Views

Cannot PUT error in Node Express app

My get and post APIs are working, but for some reason my app.put isn't. When I hit localhost:3001/contacts/1 as a PUT in PostMan, I don't even see my simple console.log: app.put('/api/contacts:id', (req, res) => { console.log('req.params.id', req.params.id); res.json(contact); }); app.put app.put('/...
Leon Gaban
1

votes
2

answer
11.9k

Views

TypeError: next is not a function

I'm running a Node.js-server and trying to test this Rest API that I made with Express. It's linked up to MongoDB using Mongoose. I'm testing the individual routes using Postman and I get an error when trying to send a PUT-request to this route: // PUT /meetings/:id // Route for editing a specific m...
SudokuNinja
1

votes
2

answer
2.1k

Views

Node.js how to set server environment PORT and NODE_ENV?

How do I set the server environment to a certain port? For instance, const app = require('express')() const isProd = (process.env.NODE_ENV === 'production') const port = process.env.PORT || 3000 I will always get false for isProd and 3000 for port I don't see the usefulness of these two lines and I...
laukok
1

votes
2

answer
537

Views

Serving react-routes with Express

I'm using react-router-dom and load components on rotes like this: ...and so on... I build this project with webpack and have only 1 single file bundle.js. and use It as static files in my server.js import express from 'express' const app = express() app.use('/', express.static('./public')) app.list...
1

votes
2

answer
1.3k

Views

knex like query dynamically add

`let add_query = '.andWhere('company_name', 'like','%marker%')'; knex('franchisee').where('franchisee_name', 'like', '%jackmarker%')${add_query} .then((resp) => { console.log('resp >>',resp) })` Hear i want to execute like query using knex npm in node js. I take variable add_query using this variabl...
jack
0

votes
0

answer
18

Views

Express/MySQL not returning same value returned by MySQL Workbench

I have a query that is perfectly working when I run it on MySQL Workbench, but when I run it on Express it is returning me all the data on my database. Please help fix? PS. posted this before but didn't get fixed. --Client $.ajax({ url: '/filter', type: 'get', contentType: 'application', data: { ca...
Matthew
0

votes
0

answer
5

Views

Jquery Response not updating the input val in ajax call

I have a input field and make a ajax call which in turn receives response as html page and json data on success , i need to update the json data to the input field in response success function //ajax function $(function(){ return $.ajax({ type: 'GET', url:'/en', contentType: 'application/json', data...
sowmiya
0

votes
0

answer
6

Views

Using MongoDB User to log into application

I set up my mongoDB to take in a user with a userID, password, firstName, lastName, email. This user needs to be able to login to my application and have it's own session to add and remove items from a store. I cannot get this user to sign in. I do have my sign-in page working and it is accepting v...
teewrecks
1

votes
1

answer
658

Views

How can i iterate over the row and print the objects value in excel in node js?

I have an array of objects as shown below: [ { 'FirstName': 'John', 'LastName': 'Parker', 'Age': '23', 'Cat': '23g', 'SOP': 'Active' }, { 'FirstName': 'Rose', 'LastName': 'Jackson', 'Age': '44', 'Cat': '44g', 'SOP': 'InActive' } ] I am using excel4node to create and write the object's data...
Rocky
1

votes
3

answer
621

Views

Get response status code in a middleware

I am building an app in which I am trying to build my own logging system for each request. For each request, I'd like to log the timestamp, the method used, the route, and finally the response code that has been sent to the client. I have the following code for the moment : // index.js const expres...
nook
1

votes
2

answer
461

Views

process.env.PORT is undefined (in LinuxCloud environment)

I've been developing a nodejs app on C9 for some time and now I'm trying to make a copy of it on my remote host. So far, in the new environment node app.js works in the console but I am unable to view the website in my browser. It seems that it is a port issue. My app.js file goes like this : var ex...
Ewan Delanoy
1

votes
1

answer
45

Views

Difference between localstorage and session [closed]

I have created user authentication with passport local strategy and i use session. Everytime the user logged in session is stored in database and the browser. In my frontend can use the user.id to store it in local storage as a key or token ?
Sadiq Mustapha Aji
1

votes
2

answer
598

Views

ERR_HTTP_HEADERS_SENT: Cannot set headers after they are sent to the client at ServerResponse

I am trying to create a simple REST API with NodeJS and Express without any database. I have stored all of my data in JSON files. The data is in the form of an array of objects. I have paths like fund-name/:portId so I am doing this: const fundName = require('./json/fund-name.json'); app.get('/fund-...
Pritam Bohra
1

votes
2

answer
64

Views

Node.js - require without assignment

I wrote a small express application and put my routes in a different file, routes.js: module.exports = function(server) { // Server is my express object server.get('/something', (req, res) => { // Stuff }); // Some other routes } To use them in my main file, server.js, I require them like this: requ...
CodeF0x
1

votes
1

answer
56

Views

req.body.username being undefined

in express js, i am using body parser to get the username. when i try to get the username, it returns undefined. Can anyone help me? app.use(session({ cookieName: 'session', secret: 'Shh_It's_a_secret', duration: 100000 * 100000 })); app.use(bodyParser.urlencoded({ extended: true })); app.get('/home...
Ank i zle

View additional questions