Skip to content
Advertisement

Tag: node.js

Sending command line arguments to npm script

The scripts portion of my package.json currently looks like this: …which means I can run npm start to start the server. So far so good. However, I would like to be able to run something like npm start 8080 and have the argument(s) passed to script.js (e.g. npm start 8080 => node ./script.js server 8080). Is this possible? Answer npm

Why is process.env.NODE_ENV undefined?

I’m trying to follow a tutorial on NodeJS. I don’t think I missed anything but whenever I call the process.env.NODE_ENV the only value I get back is undefined. According to my research the default value should be development. How is this value dynamically set and where is it set initially? Answer process.env is a reference to your environment, so you

Get data from fs.readFile [duplicate]

This question already has answers here: Why is my variable unaltered after I modify it inside of a function? – Asynchronous code reference (7 answers) Closed 6 days ago. Logs undefined, why? Answer To elaborate on what @Raynos said, the function you have defined is an asynchronous callback. It doesn’t execute right away, rather it executes when the file loading

Send response to all clients except sender

To send something to all clients, you use: To receive from clients, you use: How can I combine the two so that when recieving a message on the server from a client, I send that message to all users except the one sending the message? Do I have to hack it around by sending the client-id with the message and

Remove objects on disconnect socket.io

I’m using Nodejs and Socket.io. When the client connects, new JavaScript objects are created. Do these objects just linger forever? Should they be deleted or removed when the client disconnects? Is it even possible to remove an object? I know delete won’t work… Thanks – I guess this is more of a general question and any suggestions would be really

What is this JavaScript “require”?

I’m trying to get JavaScript to read/write to a PostgreSQL database. I found this project on GitHub. I was able to get the following sample code to run in Node. Next I tried to make it run on a webpage, but nothing seemed to happen. I checked on the JavaScript console and it just says “require not defined”. So what

How to fix Error: listen EADDRINUSE while using NodeJS?

If I run a server with the port 80, and I try to use XMLHttpRequest I am getting this error: Error: listen EADDRINUSE Why is it problem for NodeJS, if I want to do a request, while I run a server on the port 80? For the webbrowsers it is not a problem: I can surf on the internet, while

Advertisement