Tag Archives: node

Solving the problem of joi. Validate is not a function

Question:

When writing about the running of the project, the problem of joi. Validate is not a function appears

#Reason:

After checking, it is possible that the third-party module joi was not downloaded or the version is wrong

solve:

Open the PowerShell and uninstall the joi if it has been downloaded:

npm uninstall joi

Then download the module again, joi:

npm install joi

Node rerun project

NPM start project error: cannot find module ‘webpack’ problem solution

First install cnpm and then use cnpm i to install the package when stuck and then force to end the download and then install node_modules again after the error error, start the project when npm run serve reported the following error.
The correct approach: If you force to interrupt the download, you should remove the node_modules and reinstall them, no error after the end of the installation means success
PS D:\code\DA_svn\pages\index> npm run serve
> [email protected] serve D:\code\DA_svn\pages\index
vue-cli-service serve
INFO  Starting development server…
ERROR  Error: Cannot find module ‘webpack’
Require stack:
– D:\code\DA_svn\pages\index\node_modules\[email protected]@webpack-dev-server\lib\Server.js
– D:\code\DA_svn\pages\index\node_modules\_@[email protected]@@vue\cli-service\lib\commands\serve.js
– D:\code\DA_svn\pages\index\node_modules\_@[email protected]@@vue\cli-service\lib\Service.js
– D:\code\DA_svn\pages\index\node_modules\_@[email protected]@@vue\cli-service\bin\vue-cli-service.js
Error: Cannot find module ‘webpack’
Require stack:
– D:\code\DA_svn\pages\index\node_modules\[email protected]@webpack-dev-server\lib\Server.js
– D:\code\DA_svn\pages\index\node_modules\_@[email protected]@@vue\cli-service\lib\commands\serve.js
– D:\code\DA_svn\pages\index\node_modules\_@[email protected]@@vue\cli-service\lib\Service.js
– D:\code\DA_svn\pages\index\node_modules\_@[email protected]@@vue\cli-service\bin\vue-cli-service.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\pactera\AppData\Roaming\npm-cache\_logs\2021-03-09T00_59_46_004Z-debug.log

UnhandledPromiseRejectionWarning: MongoError: not authorized on elm to execute comman

Error in starting node project

UnhandledPromiseRejectionWarning: MongoError: not authorized on elm to execute command { insert: “hongbaos”, ordered: false, $db: “elm” }

The reason is that you do not have permission to connect to the database

The reason is that the database mongo.conf There is an auth = true solution

1. Comment out auth = true

2. Enter adimn to set the user name and password, and use the user name and password to access the database

Switch use admin before creating user

db.createUser(
	{
		user:"root",
		pwd:"123456",
		roles:[{role:"root",db:"admin"}]
	}
);

The node rimraf module recursively deletes the contents of the folder

When using the webpack build file project, a dist directory is generated every time. Sometimes, all the old files in the dist directory need to be deleted,

In addition to the RM – RF / dist / command, you can also use the rimraf / dist / command

The function of rimraf is to package the RM - RF command in the form of package to delete files and folders, regardless of whether the folder is empty or not

Local installation: NPM install rimraf — save dev

Global installation: NPM install rimraf – G

Use: rimraf & lt; path & gt; [& lt; path & gt;…]

api:rimraf(f, [opts], callback)

NPM run build error solution

An error is as follows

checked online related:
.
because package json file does not have to configure the build script, so the above error!
Solutions:
1. Add build script to scripts in package.json:

{
  "scripts": {
    "build": "cross-env NODE_ENV=production webpack --config webpack.config.js"
  }
}


“NODE_ENV” : user-defined environment variable
webpack “: integrated packaging command
“>config” : config file
“webpa>onfig.js” : config file, which is a Node. js module that returns a JSIN-formatted configuration information object, or the –config option to specify the configuration file

It is possible that ‘cross-env’ is not an internal or external command and is not a executable program
can be resolved by NPM I –save-dev cross-env.
The results of
Execute NPM run build, and the results will appear in the dist folder. Successful packaging!

Reference: https://www.cnblogs.com/tugenhua0707/p/9780621.html

https://www.cnblogs.com/eyunhua/p/6507100.html

Node connects to MySQL error “Er”_ NOT_ SUPPORTED_ AUTH_ Mode “solution

Perform the following query in MYSQL Workbench
ALTER USER ‘root’ @’ localhost ‘IDENTIFIED WITH mysql_native_password BY’ password ‘
when root is USER localhost of your url, and password is your password
, then run the following query to flush privileges:
flush privileges;
try using node connections after completion.
if that doesn’t work, try @’ localhost ‘

node url.parse()

Assume that this is a url http://localhost:8080/a/b/c?a=1&
protocol: ‘HTTP:’,// protocol
host: ‘localhost:8080’,
port: ‘8080’,// port
hostname: ‘localhost’, domain
hash: ‘#abcd’,
search: ‘?a=1& B = 2 ‘,
query: ‘a = 1 & amp; B =2 ‘,
pathname: ‘/a/b/c’,
path: ‘/a/b/c?a=1& B = 2 ‘,
href: ‘http://localhost:8080/a/b/c?a=1& B = 2 # ABC ‘
Url.parse () can break a complete URL into many parts, such as host, port, Pathname, path, and Query

var http = require("http");
var url = require("url");

var server = http.createServer(function(req,res){
    var pathname = url.parse(req.url).pathname;
    var query = url.parse(req.url).query;
    console.log("patname:"+ pathname);
    console.log(query);
    res.end();
});
server.listen(80,"127.0.0.1");

Completely uninstall node and NPM on MAC

NVM is installed under ~/. NVM is not installed with the previous one. I am a little obsessive, so I want to uninstall the previous one
Homebrew installed

brew uninstall node
The official website downloads the PKG installation package
A command
sudo rm - rf/usr/local/{bin/{node, NPM}, lib/node_modules/NPM, lib/node, share/man/*/node. *}
It was installed in another way
Make a script, the need to delete the file, a shuttle all kill
It will be called: uninstallNode. sh

#!/bin/bash
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
  sudo rm /usr/local/${i}
done
sudo rm -rf /usr/local/lib/node \
     /usr/local/lib/node_modules \
     /var/db/receipts/org.nodejs.*

Modify file permissions chmod 777 uninstallnodejs.sh
is executed on the command line
When you're done deleting all that stuff, you're done deleting node.
but there are a lot of node-based installed software and command-line tools that need to be reinstalled, such as react-native, supervisor,pm2 etc
need to delete the files under /usr/local/bin, actually they are just soft connections, it's all under /usr/local/lib/node_modules/.
was removed in the previous step, but you can still find it by pressing the TAB key because these soft connections still exist

Error: ENOENT: no such file or directory, open ‘E:\Program Files\nodejs\tmp\upload_38b32f25bc984333c

Look at the picture first:

The main reason for this problem is that the files you are uploading are not in the same folder
So put the folder TMP and the running JS files in the same directory, as shown in the figure below:

Then the path is changed. The first path I wrote was fs.readfile (“/ TMP /test.png”…) There is no problem changing “/ TMP /test.png” to “./ TMP /test.png”
Fs. ReadFile (“./TMP/test. The PNG “, “binary”, function (the error, the file) {
if (error) {
response. WriteHead (500, {” content-type “:” text/plain “});
response. Write (error + “\ n”);
the response. The end ();
} else {
response. WriteHead (200, {” content-type “:” image/PNG} “);
response. Write (file, “binary”);
the response. The end ();

}});

Cannot find module ‘lodash’

The scenarios in which this problem occurs vary, but the solutions are basically the same. This article takes lodash module as an example

    if Cannot find module lodash appears after the pull code is run, usually someone else USES a plug-in lodash, but you do not have it in your local environment, you can directly go to the package. Json to check if there is lodash, if there is, that proves that you do not install the lodash, use CNPM install to install it. Json package.json not found, Cannot find module lodash, global search under the file lodash, if the file is not used, then delete node_module, re-use CNPM install can be installed; Json . Just ask the relevant person to submit it, and then refer to step 1. Json, node_module package-lock. Use NPM cache clean --force to clear the cache. Then use NPM install to install.

Json copy a copy of packing-lock-. jsoncopy a copy of packing-lock. jsoncopy a copy of packing-lock. json copy a copy of packing-lock-. (Of course, if the file is u update status, then don't bother, check the update content, and then submit it)

UnhandledPromiseRejectionWarning Error: Can‘t set headers after they are sent (How to Fix)

(node:57300) UnhandledPromiseRejectionWarning: Error: Can't set headers after they are sent.
    at validateHeader (_http_outgoing.js:491:11)
    at ServerResponse.setHeader (_http_outgoing.js:498:3)

In the Node project, you encountered this error while doing module splitting.
is checked to be package.json deleted

"babel-preset-env": "1.3.2",
"babel-preset-es2015": "6.24.1",
"babel-preset-stage-2": "6.24.1"

These three modules cause these three modules not to be deleted.
is originally required by the server to render the json inside the reference file is relative. Node_modules relative to the root directory, so the items below the root directory are related to modules such as vue, Babel-Polyfill, etc.