Installing axios using npm is undefined

2019-08-25 16:05发布

问题:

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

回答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