天道酬勤,学无止境

node.js

How can I set uploaded file name?

By using 'multer' , I made it to request image file like this. And this file is stored at 'uploads' folder I set. my code is below: var multer = require('multer') var upload = multer({dest:'./uploads/'}); //var upload = multer({ storage: storage }); var app = express(); app.use(app.router); app.post('/upload', upload.single('puzzle'), function (req, res, next) { console.log(req.file); }); But I want to set my file name like 'abc.png' not 'abc' I read docs and what I found is that var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, '/uploads'); }, filename

2022-01-19 02:42:18    分类:问答    javascript   node.js   multer

Remove specific properties from Array objects in Node.js

For example I have this array, if I stringfy it it would be like this: [{"car":"Toyota","ID":"1", "Doors": "4", "price": "20.000"},{"car":"Chevrolet","ID":"2", "Doors": "2", "price": "15.000"}] How can I do for remove from the 2 cars: the doors and price. And only leave in the array "car" and "id"? For example: [{"car":"Toyota","ID":"1"},{"car":"Chevrolet","ID":"2"}] Thank you!

2022-01-19 02:41:34    分类:问答    javascript   arrays   node.js   object

How to verify laravel passport api token in node / socket application?

My question is about OAuth passport token in laravel application which is using sockets / node express sever as well. I need to implement my authentication mechanizm on socket server. Something like this article: https://m.dotdev.co/authenticate-laravel-5-user-account-in-nodejs-socket-io-using-json-web-tokens-jwt-f74009d612f8. Already Im building this mechanism with my own token. But I would prefer to use token generated for my Laravel API. My point is how is this token builded ? Which fields of user are there and which keys are needed to check if token is valid on node server side? Is that

2022-01-19 02:31:57    分类:问答    node.js   api   jwt   token   laravel-passport

how to give file name a input in baby parser

I am trying to use baby parser for parsing csv file but i am getting below output if i give file name file and code are in same directory my code: var Papa = require('babyparse'); var fs = require('fs'); var file = 'test.csv'; Papa.parse(file,{ step: function(row){ console.log("Row: ", row.data); } }); Out put : Row: [ [ 'test.csv' ] ]

2022-01-19 01:50:53    分类:问答    node.js   csv   papaparse

ASP.NET Core The system cannot find the file specified

I have followed this tutorial on getting angular and ASP.NET Core running together. The initial build worked fine but after updating angular packages I am receiving the following error on startup of the application(I also had to reinstall nodejs in the process, not sure if this is related): The error is on the following line: app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); The error itself does not provide me with any usefull information to track down the issue. I get a: System.AggregateException => Count = error CS0103: The name

2022-01-19 01:38:30    分类:问答    node.js   angular   asp.net-core   webpack-dev-middleware

Stream upload file to Azure blob storage with Node and graphql

I need to store an image to Azure blob storage using nodejs and apollo-server-express.I am using createBlockBlobFromStream for storing but it requires stream length. how can I find the stream length? Is there any better way to store images to azure blob storage using graphql uploadImageFunc is called by the resolver by passing the args const fs = require('fs') const azure = require('azure-storage') const blobService = azure.createBlobService("connection string") const uploadImageFunc = async function(args) { return args.file.then(file => { const {createReadStream, filename, mimetype} = file

2022-01-19 01:08:27    分类:问答    node.js   azure   graphql   apollo-server

Starting Node with Forever and --prof option V8 Log file not created

I am trying to run my Node App using "forver" module , I also want to pass "--prof" option for profiling my app. The command I am using is NODE_ENV=staging PORT=3000 NODE_CONFIG_DIR="/domains/serving/src/config" forever start -c "node --prof" -l /var/log/forever.log -e /var/log/forever_error.log -o /var/log/forever_output.log -a /domains/serving/src/bin/www Or NODE_ENV=staging PORT=3000 NODE_CONFIG_DIR="/domains/serving/src/config" forever start -c "node --debug=3048 --prof" -l /var/log/forever.log -e /var/log/forever_error.log -o /var/log/forever_output.log -a /domains/serving/src/bin/www

2022-01-19 01:07:09    分类:问答    linux   node.js   profiling   v8

Send an http request and receive push data

I want my Node.js code to send an http request to another server. It works fine using the code below. My problem is that the server in question then should push data, and the connection is closed right after the request. For instance, if I open the page using my browser, I get push data from the server and my page is refreshed by the browser. The question is: How can I get the push requests (from the other server) that follow my http request in my Node server? I tried to keep the connection alive using "keep-alive", but this does not change anything. Example code: var http = require("http")

2022-01-19 01:01:37    分类:问答    node.js   push

NodeJS promise resolution

const a = [1, 2, 3, 4, 5]; const f = () => new Promise((resolve, reject) => resolve(4)); const g = () => { Promise.all(a.map((member) => f().then((res) => res))) .then((result) => { console.log(result) }); } g(); Why do I not need another then attached to {return res;} here? I read that when you have a return (something)inside a then, another then must be attached, but its not the case here. Help?

2022-01-19 01:00:22    分类:问答    javascript   node.js   promise

How to deploy node app dependencies? How is possible to ensure to install certain versions of a package with npm?

What's the best way to deploy the dependencies for a node app. How is possible to ensure to install certain versions of a package with npm. Are there like recipe files as the requirements.txt with python's pip?

2022-01-19 00:48:01    分类:问答    node.js   npm