简体   繁体   中英

Installing axios using npm is undefined

I am new to Axios and I am dealing with my first issue! I installed it with

npm install axios

and I get this error! enter image description here

Also, I get an ENOENT error: no such file or directory, open /path/../../../ Can someone explain the reason?

Thank you!

UPDATED :

I no longer get the ENOENT error.

THE FIX :

Was to change the name directory to something else rather than axios to axiosapi or anything else!

NEW ISSUE :

const axios = require('axios');

const api_url = 'https://opentdb.com/api.php?amount=1';
console.log(api_url);


axios.get(api_url)
.then(
    response => {
        if(!response.ok) {
        throw Error(response);
        }
        return response;
    }
)
.then( response => console.log(response) )

.catch( err =>  console.log(err) )

Uncaught ReferenceError: require is not defined at axioss.js:1

If you are installing globally use npm install -g axios.

Otherwise you need to create a project in your current directory: npm init -y

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM