Tag Archives: node.js

[Solved] node.js Upload Files Error: Multipart: boundary not found multer

Today, when the front-end uses Vue to transfer files with formdata, the background node reports an error

Multipart: Boundary not found multer

It is found in the front console that the file file transmitted by the interface is null {}, because it is set when Axios requests

the Header of Content-Type is multipart/form-data

It is found that there is no boundary parameter later, except multipart/form data

multipart/form-data;boundary :****************

There should also be a series of boundary parameters. First of all, do not splice the contents behind the boundary, otherwise you need to reconfigure all the content parameters yourself.
later, it is found that it is the reason for the request method, and you need to use ajax to make the request.
the solution is as follows

// upload the files
export function reqUploadImg(file, user_id) {
  return axios({
    url: '/uploadImg',
    method: 'POST',
    Headers: {
      "content-type": "multipart/form-data",
    },
    data: file,
    params: { user_id }
  })
}

This problem can be solved. It will automatically splice a string later, or “content type”: “multipart/form-data” in “multipart/form-data” will also be spliced automatically if it is set to fasle, but after personal experiments, it is found that the types have changed into JSON format, which is automatically generated by Axios source code

[Solved] error: mongoosserverselectionerror: connect econnreused 127.0 0.1:27017

Mongodb suddenly reported an error, the foreground could not get the data, and the mongodb software could not be opened

node:22368) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at NativeConnection.Connection.openUri (D:\HBuilder work place\huaRui\2.0\serve\node_modules\mongoose\lib\connection.js:797:32)

Solution: Task Manager — Service — mongodb — Open

[Solved] NPM run build package error: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

1. Phenomenon

It has always been normal. Suddenly one day, an error is reported when packing. The key information is as follows:
ineffective mark compacts near heap limit allocation failed - Javascript heap out of memory
the details are as follows:

2. Solution

All kinds of data say that node memory overflow , and solutions are also given,
for example: – max_old_space_Size = 4096 and so on, but it doesn’t work for me. (if you refer to mine, it doesn’t work, you can look at the other methods mentioned above)
later, I saw a solution, which worked
1, CMD Global install increase memory limit
NPM install -g increase memory limit

2, CD enter the project directory and execute:
increase memory limit

3. Repack
NPM run build

(node:268660) UnhandledPromiseRejectionWarning: Error: Cannot find module ‘yallist‘

NPM command error in vscode

In Vue (node: 268660) unhandledpromiserejectionwarning: error: cannot find module ‘yallist’ problem solving delete the under C: \ users \ [current user name] Npmrc file Npmrc file content:

In Vue (node: 268660), unhandledpromiserejectionwarning: error: cannot find module ‘yallist’ problem solving

Delete the under C: \ users [current user name] Npmrc file

. Npmrc file content:

cache=C:\Software\Tool\nodejs\node_cache
prefix=C:\Software\Tool\nodejs\node_global
registry=https://registry.npm.taobao.org

Using ts-node to Execute .ts files Error [Solved]

When learning typescript, you want to execute the TS file. First install the TS package, then use the TSC command to execute it, compile it into a JS file, and use node xxx.js to execute it. However, this is troublesome. Later, you want to use TS node to directly execute it and simplify the steps. An error is reported:

It is found that the corresponding package needs to be installed to compile:

Solution:
 
npm install -D tslib @types/node

Node.js Error: throw er; // Unhandled ‘error‘ event [How to Solve]

Original console output:

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at new NodeError (node:internal/errors:371:5)
    at ServerResponse.end (node:_http_outgoing:846:15)
    at Server.<anonymous> (D:\files\Web_videos\Node\server\app.js:30:13)
    at Server.emit (node:events:390:28)
    at parserOnIncoming (node:_http_server:951:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
Emitted 'error' event on ServerResponse instance at:
    at emitErrorNt (node:_http_outgoing:726:9)
    at processTicksAndRejections (node:internal/process/task_queues:84:21) {
  code: 'ERR_STREAM_WRITE_AFTER_END'
}

Error reason:

The port number is occupied.

Solution:  

Modify the port number, or kill the port number and restart the project

How to kill the port number:

1. Enter the CMD command window and write netstat – ano|findstr “8080”

2.taskkill -PID 13512 -F

Node.js Error: “Error: EBUSY: resource busy or locked, stat“

abnormal

Error: EBUSY: resource busy or locked, stat 'C:\swapfile.sys'
    at Object.statSync (node:fs:1536:3)
    at D:\NodeJs\node-demo\demo\world.js:7:24
    at FSReqCallback.oncomplete (node:fs:188:23) {
  errno: -4082,
  syscall: 'stat',
  code: 'EBUSY',
  path: 'C:\\swapfile.sys'
}

Node.js v17.1.0

error code

var fs = require('fs');

var rootPath = 'C:\\';
fs.readdir(rootPath, function (err, files) {
    for (var i = 0; i < files.length; i++) {
        var p = rootPath + files[i];
        var stats = fs.statSync(p);
        console.log(rootPath + 'Is it a directory:' + stats.isDirectory())
    }
});

Reason

Prompt error: EBUSY: resource busy or locked, stat indicates that the resource file is busy or locked, that is, the C:\swapfile.Sys file. But there is no such file in the C disk directory, even in the hidden file. But it can be found by opening everything software
is a system file.

Solution:

I don’t know how to solve it. The online solution seems to be invalid, so I can only block the file.

Correct code

var fs = require('fs');

var rootPath = 'C:\\';
fs.readdir(rootPath, function (err, files) {
    for (var i = 0; i < files.length; i++) {
        var p = rootPath + files[i];
        // Skip when encountering swapfile.sys file or System Volume Information directory
        if (p.endsWith('swapfile.sys') || p.endsWith('System Volume Information')) {
            continue;
        }
        var stats = fs.statSync(p);
        console.log(rootPath + 'Is it a directory:' + stats.isDirectory())
    }
});

[Solved] Syntax Error: Error: Cannot find module ‘cache-loader‘

The following problem occurs. It should be that some dependent packages are not downloaded successfully and need to be reinstalled

Solution:
1. Enter the folder directory of the project and delete the node_ Modules file and package-lock.json file. Note that it is not package.json (if it cannot be deleted, check whether the project is open and try again after closing)
2. Enter NPM install installation dependency

3. Start the project and it can be started normally.