All Questions

Tagged with
Filter by
Sorted by
Tagged with
1286 votes
34 answers
1.4m views

Using Node.js as a simple web server

I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same experience as when you read normal web pages). ...
idophir's user avatar
  • 14.6k
661 votes
31 answers
848k views

How do I run a node.js app as a background service?

Since this post has gotten a lot of attention over the years, I've listed the top solutions per platform at the bottom of this post. Original post: I want my node.js server to run in the background, ...
Peter Kruithof's user avatar
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
310 votes
20 answers
381k views

How to make a node.js application run permanently?

On a Debian server, I installed Node.js. I understand how to launch an app from putty with this command line: node /srv/www/MyUserAccount/server/server.js and get to it on the address 50.51.52.53:...
Sam's user avatar
  • 3,529
184 votes
17 answers
627k views

npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'

I just want to install socket.io to my project which is located on 3.chat folder. But when I run following command it shows following Warnings.And its not created a node_modules directory inside my ...
user avatar
57 votes
15 answers
105k views

Missing credentials for "PLAIN" nodemailer

I'm trying to use nodemailer in my contact form to receive feedback and send them directly to an email. This is the form below. <form method="post" action="/contact"> <label for="name"&...
igolo's user avatar
  • 571
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
44 votes
7 answers
57k views

How to run pm2 so other server users are able to access the process?

When I start my Nodejs app with pm2, other server users are not able to access the process. Even if I start pm2 from a custom directory (not current user's ~/, what pm2 is using by default): HOME=/...
Nik Sumeiko's user avatar
  • 8,493
43 votes
4 answers
86k views

how to automatically restart a node server?

We are finishing development of a project, the client is already using it but occasionally some errors occur - crashing the server. I know I could register a service as 'upstart' script on linux, in ...
unsafe_where_true's user avatar
41 votes
2 answers
36k views

Multipart HTTP response

The goal is for a Node.js / hapi API server to respond to a browser's AJAX request with two things: A media file (e.g. an image) A JSON object with metadata about the file These are two separate ...
Seth Holladay's user avatar
39 votes
1 answer
18k views

How do you authenticate a server to Firebase?

I have an app written on Firebase. Security rules and client side code aren't quite enough to make my app work. I need to connect a server to do a few tasks: Cleaning up denormalized data that's ...
mimming's user avatar
  • 14k
38 votes
1 answer
22k views

What does the command "node ." do?

The README document of my node server instructs me to run this command on my command prompt. node . What does this command do? How does it start my node server? My package.json contents are { "...
Rogen George's user avatar
35 votes
1 answer
34k views

new URL() - WHATWG URL API

I'm messing around with node and I'm trying to get an instance of the URL class (because of those handy properties). Like: const { URL } = require('url'); (...) http.createServer((request,response) =&...
Thom's user avatar
  • 544
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
33 votes
6 answers
66k views

I have Godaddy Shared Web Hosting I need to host node.js website can host site? [closed]

Anyone have an idea to host a site or reference for how to install a node server on Godaddy. We have Godaddy shared hosting which provides full Cpanel and looking to customize this shared hosting. ...
Bhavik Limani's user avatar
30 votes
1 answer
62k views

Node.JS Error- process.env.NODE_TLS_REJECT_UNAUTHORIZED. What does this mean?

I am new to back-end development. And I am really enjoying writing code in node. However, there are few things I just can't seem to grasp. I kept getting the following error: Error: ...
Mihir Patel's user avatar
  • 2,272
30 votes
5 answers
47k views

Generate Swagger Document for existing NodeJS server

According to Swagger website, there are two approaches: Bottom-up and Top-down. I have an existing NodeJS server that I'd like to deploy in the Azure enviroment, that require a swagger document (API ...
Ernani's user avatar
  • 1,009
22 votes
9 answers
21k views

Heroku build failing due to Yarn and npm lockfile conflict

I'm trying to deploy a React Web app on Heroku using the Heroku CLI. However when I run, git push heroku master from my project folder it throws an error as: Counting objects: 213, done. Delta ...
SeaWarrior404's user avatar
21 votes
2 answers
27k views

Ubuntu - nodejs - npm install -g > Error: EACCES: permission denied, mkdir

Was having a issue installing a NodeJS npm package. On a Digital-Ocean Droplet Ubuntu (14.04) server. npm install -g PACKAGE-NAME I even tried with sudo had the same error. Error message: ...
K-G's user avatar
  • 2,871
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
16 votes
6 answers
21k views

Firebase Hosting with own server node.js

I have webapp with firebase database. I would like hosting the app on firebase. My app has own server nodejs and using websockets. How can I host my app on Firebase? And how can I run my own server on ...
jul56's user avatar
  • 161
16 votes
3 answers
14k views

Server Side Implementation of requestAnimationFrame() in NodeJS

I have some questions regarding the wildly used requestAnimationFrame() functions. Recently I came across some implementation in multiplayer games who used it on the client instead of the server side. ...
HansMusterWhatElse's user avatar
16 votes
4 answers
14k views

NodeJS (Server): ReferenceError: require is not defined when type: module

On Node 13.8 I'm trying to use import / export. EG: import {ChatClient, Message, MessageParser} from './chat-client/module.js'; But when i do this, I get SyntaxError: Cannot use import statement ...
TheBritishAreComing'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
13 votes
4 answers
41k views

TypeError: require(...).listen is not a function

I wrote this, but errors come up and i dont know how to fix var http = require('http'); var clientHtml = require('fs').readFileSync('client.html'); var plainHttpServer = http.createServer(function (...
user1467328's user avatar
13 votes
7 answers
3k views

serve content from file vs database in node

I am making a new version of a old static website that grew up to a 50+ static pages. So I made a JSON file with the old content so the new website can be more CMS (with templates for common pages) ...
Rikard's user avatar
  • 7,625
13 votes
1 answer
7k views

nodemon is slow to restart the server

I've recently reinstalled node package manager npm install nodemon -g which grabbed the latest build. But when I run nodemon server.js and I save changes to files, it's extremely slow to restart the ...
chasnz's user avatar
  • 179
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
12 votes
3 answers
13k views

How to properly close a Node.js TCP server?

I couldn't find a clear answer on Google or SO. I know a net.Server instance has a close method that doesn't allow any more clients in. But it doesn't disconnect clients already connected. How can I ...
Aviv Cohn's user avatar
  • 16.3k
11 votes
5 answers
24k views

Running svelte dev on server

I am running svelte like this on my server: $ npm run dev Your application is ready~! 🚀 - Local: http://localhost:5000 ────────────────── LOGS ────────────────── Which is great. However, ...
DaraJ's user avatar
  • 2,792
11 votes
1 answer
29k views

How to use the optional hostname parameter in Node.js server.listen()

From what I've read in tutorials so far, the optional hostname parameter to server.listen(port[, hostname][, backlog][, callback]) has always been either 127.0.0.1 (loopback), 0.0.0.0 (listen on every ...
Yibo Yang's user avatar
  • 2,383
11 votes
3 answers
2k views

Auto save server architecture

I want to save a lengthy form's inputs at the server. But I don't think making db calls on each auto-save action is the best approach to go for. What would constitute as a good approach to solve ...
amit's user avatar
  • 10.1k
11 votes
1 answer
17k views

protocol packets out of order

I recently uploaded my node.js app on A2 Hosting and I get this error : { Error: Packets out of order. Got: 80 Expected: 0 at Parser.write (/home/westudec/public_html/myapp/node_modules/mysql/...
Aaron Aben Danan's user avatar
10 votes
3 answers
14k views

Heroku: How to deploy a node app with client and server running on different ports?

I have a nodejs API as server and React/Redux app as client located in one git project: https://github.com/lafisrap/fcc_nightlife.git I want to deploy it on Heroku using the heroku cli. The ...
Michael's user avatar
  • 6,963
10 votes
2 answers
2k views

Redirecting using "pure" Node.js from inside a callback function

The following is an MCVE of my server.js code: let fs = require('fs'); let http = require('http'); http.createServer((req, res) => { // Handles GET requests if(req.method == 'GET') { ...
vrintle's user avatar
  • 5,541
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
10 votes
1 answer
4k views

Node.js HTTP2 server Error: socket hang up

Given the latest version of Node.js with experimental HTTP2 support: $ node -v v9.2.0 An HTTP2 server: var options = { key: getKey(), cert: getCert(), allowHTTP1: true } var server = http2....
Lance's user avatar
  • 77.1k
10 votes
3 answers
27k views

Run NodeJs server in Android

Is it possible to run NodeJs server in android device (like linux devices not android apps). If possible please help me to do it. And is it possible to start mongo server on Android device? My devices:...
Hossain Khademian's user avatar
9 votes
4 answers
24k views

Using multer diskStorage with Typescript

I'm translating a node.js server to typescript. My funcion with node is: const storage = multer.diskStorage({ destination: function (req, file, cb) { const dir = './uploads/'; ...
Diego's user avatar
  • 496
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
9 votes
4 answers
14k views

What is the best way to communicate between two servers?

I am building a web app which has two parts. In one part it uses a real time connection between the server and the client and in the other part it does some cpu intensive task to provide relevant data....
Sanjit Roy's user avatar
9 votes
2 answers
2k views

Mongodb Secure Server Setup with Mongoose

The setup i am trying to success is to have a node process which create databases, and other servers access those databases with a secure way. So my idea was to create the database from node with a ...
Honchar Denys's user avatar
9 votes
3 answers
14k views

Generate unique api keys for user in node js application for access to your apis

how to generate API Keys for the user of your nodejs application on the basis of different parameters of the user in the database for giving access to our server endpoints.
Paras Patidar's user avatar
8 votes
3 answers
6k views

MongoDB error as setup Wizard ended prematurely, while installing it on windows 10

I have downloaded MongoDB from the official site as an .msi file and during installation it stops and freezes and after half an hour, and gives an error as the setup wizard ended prematurely. I have ...
GD- Ganesh Deshmukh's user avatar
8 votes
4 answers
9k views

I can't keep my server running once I close terminal or my ssh session

I have never set up a server before but since Parse announced that they are closing down I thought I might give it a shot. I have followed along with this tutorial and have managed to migrate my Parse ...
Shayno's user avatar
  • 798
8 votes
1 answer
4k views

Why node server has to be restart on file change?

Why is it necessary to restart a NodeJS server when there is a file change? Do other servers like Apache, IIS, nginx require this as well or can they restart automatically?
rajagopalx's user avatar
  • 3,072
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
8 votes
1 answer
10k views

Prisma How to automatically update "updatedAt" field of parent element when a child element is created or updated?

Let's say I have this schema: model User { id String @id @default(cuid()) name String email String profile Profile? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } ...
Shamxeed's user avatar
  • 412
7 votes
2 answers
4k views

Why are there multiple PM2 processes listed on my server?

I have a Node application running on a production server using PM2. When I ssh into the server and run htop I can see multiple PM2 God Daemon processes listed. I don't understand why there would be ...
scottmcallister's user avatar

1
2 3 4 5
52