All Questions

Tagged with
Filter by
Sorted by
Tagged with
650 votes
6 answers
187k views

Express.js - app.listen vs server.listen

This may be a very basic question but I simply don't get it. What is the difference between creating an app using Express.js and starting the app listening on port 1234, for example: var express = ...
Tamas's user avatar
  • 11.1k
49 votes
2 answers
28k views

Difference between a server with http.createServer and a server using express in node js

What's the difference between creating a server using http module and creating a server using express framework in node js? Thanks.
Koushik Das's user avatar
  • 10.2k
34 votes
5 answers
54k views

MongoError: Topology is closed, please connect despite established database connection

I am writing a web application that uses asynchronous database requests as a part of the api. Currently, I have an async express route that awaits function returns from async functions. Both of these ...
CameronBurkholder's user avatar
23 votes
4 answers
28k views

How to serve ReactJS static files with expressJS?

The Problem I have successfully served the index.html file of my React app, but the index.js that replaces <root> in the html file with my first React component is not triggering on ReactDOM....
gpsugy's user avatar
  • 1,259
16 votes
2 answers
37k views

I want to make href tag dynamic and value will be populated and i have ejs template

Sample code snippet: index.ejs <p><a href="<%=link%>" class="btn btn-primary" role="button">Download</a></p> app.js var express = require('express'); var ...
Sagar Rana Magar's user avatar
13 votes
2 answers
31k views

Node, Express - CANNOT GET route

I am building an Express app and having some issues with routing. My '/' route is working perfectly, however other routes are not. I've looked into other questions people have posted and these have ...
Jared's user avatar
  • 641
12 votes
2 answers
23k views

Does Express disable CORS by default?

I have been asked to make sure that a new express server that I've set up enforces against Cross Origin Resource Sharing (CORS) unless the request is coming from a particular URL. I have found the ...
judgejab's user avatar
  • 529
12 votes
1 answer
41k views

WebSocket connection to 'ws://localhost:3000/' failed: Connection closed before receiving a handshake response

I took a game that my friend made and wanted to make it playable across browsers by sending keypress data between peers with WebRTC and websockets. However, I get this error in the console: ...
Yasin Hosseinpur's user avatar
10 votes
1 answer
5k views

Express: Is it necessary to respond with status 200?

Is it necessary to respond with a status 200 code or is it the default behavior? response.json({ status: 'OK', }); vs. response .status(200) .json({ status: 'OK', }); When I hit the ...
marcobiedermann's user avatar
9 votes
2 answers
7k views

How to setup routes with Express and NGINX?

I'm trying to configure an Express server with NGINX as a reverse proxy. NGINX to serve static files, and Express for the dynamic content. Problem : The normal root link works (website.com) , but ...
Sai Datta's user avatar
  • 905
8 votes
4 answers
9k views

How to use a local version of pm2 in node_modules directory to keep a server alive?

I want to keep my node server alive. Therefore I use pm2 but if I try to start my server with pm2 start index.js I get the message: pm2: command not found So, I wanted to ask how to use local pm2 ...
Operator's user avatar
7 votes
2 answers
5k views

How can I host my API and web app on the same domain?

I have a Rails API and a web app(using express), completely separate and independent from each other. What I want to know is, do I have to deploy them separately? If I do, how can I make it so that my ...
corasan's user avatar
  • 2,684
7 votes
1 answer
10k views

How do I refresh browser from server-side with node.js?

I want to reload page when my html files are changed (while development) because of HMR bug in html-webpack-plugin and webpack-dev-middleware (webpack-hot-middleware) interop. Here are two ...
zerdox's user avatar
  • 855
7 votes
1 answer
10k views

Socket.io using node.js with no express at all?

So I want to create a node.js server using socket.io, but I am more of a beginner, and find the express package rather confusing syntactically. I know that I should learn how to use express and app.js,...
Programah's user avatar
  • 179
6 votes
3 answers
5k views

Disable TLS 1.0 & 1.1 OR only use TLS 1.2 and greater in Node.js Express

How can I block TLS 1.0 and TLS 1.1 on my Node.js Express server? I'm using a traditional server setup script: const app = express(); export const server = app.listen(3000); I'm slightly confused why ...
ForgetfulFellow's user avatar
6 votes
1 answer
3k views

Restrict access to Node.js using Express

I do have a running node.js script located in a server. What i want is that it doesn't get directly accessed from browser and also i want that only certain domains/IP-s can call it! Is it possible?!
J Mon's user avatar
  • 89
5 votes
3 answers
8k views

Get the number of Requests in Express

I would like to know if is there any way of getting the total number of request in a certain path with Expressjs?
user avatar
5 votes
1 answer
15k views

Nodejs : ReferenceError: express is not defined [closed]

I begin to use Nodejs to create web servers, and for this, I use express module. Then, I intalled it with command : "sudo npm install -g express". But after lanched the program, this error occured : ...
Loufouh's user avatar
  • 85
5 votes
2 answers
11k views

Calling python script with node js express server

With below code I have created a HTTP server on port 3000 and have added some get parameters. I want to invoke a python script with this express.js server code such that when I hit localhost:3000/key1/...
Nikita Gupta's user avatar
5 votes
1 answer
2k views

Difference between app.get() and app.route().get()

What is the difference between these two statements: app.get('/',someFunction); app.route('/').get(someFunction); Please note I'm not comparing router.get and app.get
LonelyDaoist's user avatar
5 votes
1 answer
1k views

res.sendFile() Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

I'm using express to build a simple server. Everything works, but I'm getting this annoying error in the console every time I try to hard-refresh (cntr + R) my page. Error [ERR_HTTP_HEADERS_SENT]: ...
Stichiboi's user avatar
5 votes
1 answer
122 views

Accessing express server from different geo location

So me and my friend are working on a MERN Stack app, I am working on backend(Node.js) and he is working on Frontend(React.js). We are from different places, My Question is how he can access my ...
mk2683's user avatar
  • 617
4 votes
2 answers
11k views

Delete file after using response.download() in node.js?

I'm working on an app which has a server that downloads files to the client's device using response.download(). (I'm using node.js, express, and fs) Once these files are downloaded, they are just ...
TheDeveloperNextDoor's user avatar
4 votes
2 answers
2k views

NodeJS cluster, Is it really needed?

I decided that i want to investigate what is the best possible way to handle big amount of traffic with NodeJS server, i did a small test on 2 digital ocean servers which has 1GB RAM / 2 CPUs No-...
Roy Hershko's user avatar
4 votes
1 answer
2k views

Node Express does not handle parallel requests

I just created a NodeJS Express server to understand the working of NodeJS. I have learned that NodeJS can handle a large number of API requests simultaneously given that CPU intensive tasks are not ...
Zeeshan Shamsuddeen's user avatar
4 votes
2 answers
2k views

Cannot get app.css, main.js, other files to load using an Express server

I have the following code: var express = require('express'); var app = express(); var server = require('http').Server(app); app.get('/', function(req,res){ res.sendfile(__dirname + '/index.html'); }...
Nick Mandel's user avatar
4 votes
1 answer
4k views

node.js + express + socket.io cannot load javascript files into index.html

I'm developing an application and the server is currently set up and working well. This is the index.html that shows when you access the server: <!doctype html> <html> <head> ...
Wlbck's user avatar
  • 113
4 votes
2 answers
2k views

How to serve static files in ExpressJS on some paths and not others

How can I serve static files with ExpressJS only from some of paths, while not for others? To be more specific, I want to serve static files from all paths except /files (in case of request to this ...
Petr Marek's user avatar
4 votes
2 answers
49k views

Refused to execute script from because its MIME type (...) and strict MIME type (...)

Hi all I work currently on Express and get this error message trying to open my index.html : Refused to execute script from 'http://localhost:7500/app.bundle.js' because its MIME type ('text/html') ...
HoCo_'s user avatar
  • 1,352
4 votes
1 answer
1k views

Cannot POST with a binary file to a Node.js Express server [closed]

I am currently trying to pass a simple text file from Postman onto a Node.js server in order to save the text file into a folder. I have replicated the code found on this post: Using POST data to ...
Lexington Brill's user avatar
4 votes
0 answers
689 views

How to parse JPEG from an API response and send to frontend in Node.js/Express

I'm using Google's Street View Image API to get a jpeg which I then want to pass in a response body from my Node.js/Express backend to my frontend. Currently, my getStreetView function gets a correct ...
Mattie Lents's user avatar
4 votes
0 answers
3k views

Extremely Long TTFB on localhost (Node/Express)

I'm experiencing extremely long TTFB on my localhost node/express server. On average each request's(including static resource) TTFB is around 1s, occasionally up to 7s(I guess this is NOT normal) ...
WreckingBall's user avatar
  • 1,298
3 votes
1 answer
2k views

Do browsers automatically request index.html when connecting to a server?

I'm creating a web server using Node & Express. I've set up express.static on my express instance to point to a folder called public that contains index.html, but I've yet to set up any routes. ...
irishjauntingcar's user avatar
3 votes
2 answers
4k views

How to solve CORS error in nodejs while using Postman?

I created a REST Api using nodejs and mongodb and i wanted to test it in postman but while doing so I am getting a CORS error. var express = require('express'); var log = require('morgan')('dev'); ...
Himanshu Ranjan's user avatar
3 votes
3 answers
55k views

how to fix GET net::ERR_FAILED

i am very very new to backend and express js. I wanted to fetch data from my rest api but it is sending this error net::ERR_FAILED. //my api const express = require("express"); const app = ...
DjBillje Official's user avatar
3 votes
4 answers
4k views

How to return error message objects to the client in Express?

I have this block of code: router.post('/users/login', async (req, res) => { try { const { email, password } = req.body const user = await User.findByCredentials(email, password) ...
kapsztat12's user avatar
3 votes
1 answer
629 views

Using both http-server and node express server

I've seen the following setup for a node express server: server.js import { Server } from 'http'; import Express from 'express'; const app = new Express(); const server = new Server(app); Since ...
Paulos3000's user avatar
  • 3,455
3 votes
2 answers
6k views

REST API best practise for routes

I wonder what is the best practise when creating REST APIs for the following scenarios when an Order is a resource: Get all the orders in the Database. (surely not a practical scenario, only for ...
Zeeshan Shamsuddeen's user avatar
3 votes
1 answer
9k views

express.js - server listening but localhost refused to connect

Trying to get started with setting up basic server. This is my code: const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('this is fubar'); }) ...
roncook's user avatar
  • 297
3 votes
1 answer
429 views

What exactly is an environment variable in Node/Express?

I know this is a relatively simple question, but I do not see this being asked. In Node/Express, I always set this : var port = PROCESS.env.PORT || 9000 and I know that PROCESS.env.PORT is my ...
Pilkington's user avatar
3 votes
2 answers
2k views

Developer workflow: Does it matter which port is used during development?

Are there any differences between choosing this or that port? Are there any standards for picking a port? I'm just looking for the "why" a particular port was picked to be used. There doesn't appear ...
The cows are in the Meadow's user avatar
3 votes
1 answer
213 views

Add an exception to ExpressJS app.use()

I'm working on a NodeJS project, and using Express as my routing framework. I have a register form in my site, and a login form, both of which send requests to /users (/register and /login ...
Jo Colina's user avatar
  • 1,884
3 votes
0 answers
42 views

Why I can't get multiple data from MongoDB? Where I can insert on the same collection [duplicate]

I am using express server with MongoDB. Here in a collection called "request" I am able to use the insertOne, findOne, but I when I try to use find oparator it's getting some weird result. I ...
Shahadat Hossain's user avatar
3 votes
0 answers
184 views

Unable to use bootstrap with Node(express) server because DOM is not loaded outside of browser

I am trying to use bootstrap from npm, but bootstrap requires document from DOM. This is an issue because I want to use const bootstrap = require('bootstrap'); so that bootstrap is loaded globally, ...
ItsMeTheKing's user avatar
3 votes
1 answer
6k views

POST http://localhost:3000/api/users/login 404 (Not Found)

So I have a login form that currently looks like that : import React, { useState, useEffect} from "react"; import { Form, Button, Row, Col } from "react-bootstrap"; import { Link } ...
Radoslav Stanev's user avatar
3 votes
0 answers
4k views

Error: invalid input syntax for type integer: "" on express server with postgres backend

Hoping some can please assist with the following express server error as unsure what to look for and why this type of error keeps on appearing. It is using a postgres db backend. It seems to also ...
ArthurJ's user avatar
  • 799
3 votes
1 answer
5k views

How do I add a certifcate of a third party api to my app in Heroku?

My backend service calls a third-party API (Kamer van koophandel) in order to retrieve some data. However this API requires me to set a certificate. Locally it is working but when I push it to Heroku ...
Kevin Wilmink's user avatar
3 votes
0 answers
884 views

NodeJS response takes a long time

I've made a simple request but sometimes, it takes a long time to get an answer. Chome DevTools shows me that TTFB (Time To First Byte) is often more than 10 seconds. Here is my query. I'm using ...
Valentin Duboscq's user avatar
3 votes
1 answer
1k views

Fix lag in socket.io multiplayer game

i'm trying to reproduce a simple game in multiplayer (max 2 players).I'm using javascript,node.js,socket.io and express to do that. It was all good but from when i activated the main cycle in the ...
ImFireblade's user avatar
3 votes
0 answers
780 views

Stripe android app connect to Node.js server

I'm working a project to integrate Stripe's payment service to my android app. I have the basic client code setup. Card card = new Card("4242424242424242", 12, 2016, "123"); boolean validate ...
lhsieh814's user avatar

1
2 3 4 5
15