node. js cannot find module ' MySQL '

Source: Internet
Author: User

Under the Windows platform, test the Nodejs connection to the MySQL database.

First install the MySQL dependency package in the console

At first I was in the corresponding JS located in the directory under the installation of MySQL support, the result is:

When I saw so many warn, I thought I had a problem with my outfit, so I was ready for a global installation, NPM install-g MySQL

There is no error and warn.

However, when JS is executed, an exception is thrown

The reason is: After successful installation, the MySQL dependency package is found in the C:\Users\ Chen \appdata\roaming\npm directory, and the JS file does not correspond to the path that is introduced into the MySQL module.

If the JS file is not in the user directory, put JS in the E-disk Nodejs folder, run node Test14_mysql.js will be reported cannot find module ' mysql ' Error

This is because node is executing mysql.js in the E:\NodeJS directory, and node cannot find the MySQL module in the Nodejs directory, so this error is reported.

Workaround:

You can put the JS file in the user directory, and then node test14_mysql.js;

You can also install the MySQL dependency package in the Nodejs directory, and then node test14_mysql.js;

There are two ways to install a dependency package in the Nodejs directory:

1. Direct console into the Nodejs directory, then npm install MySQL

2. Create a Package.json file in the Nodejs directory, add the MySQL dependency, and then execute the NPM install in the Nodejs directory, that is, in fact, I started the installation of the successful, but was warn to scare

node. js cannot find module ' MySQL '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.