Code Monkey home page Code Monkey logo

Comments (3)

 avatar commented on June 8, 2024

This is how I got stocks.js to work on my setup using VueJS.

require('stocks.js')
const stocks = new Stocks('YOUR_API_KEY')

module.exports = {
  fetchData: symbol => {
    const options = {
      symbol: symbol,
      interval: '1min',
      amount: 1
    }

    return stocks.timeSeries(options)
  }
}

Where here I export the fetchData function and can pass it a symbol to then have it return the data.

However, I don't necessarily like having to use commonjs require statements as it throws this warning on webpack, Critical dependency: the request of a dependency is an expression.

Is there a way to not use the commonjs require with stocks.js and instead use ES6 import, but what would we be importing since import stocks from 'stocks.js' is not correct since you can't do stocks.Stocks('API_KEY')

So I think me and @ilkertuna are looking for the correct way to use stocksjs with ES6 imports as the examples look more focused on just <script> tag usage.

from stocks.js.

 avatar commented on June 8, 2024

Actually, it looks like PR #6 might solve this issue whenever that gets merged

However, until that gets resolved, what I've done, is placed the dist/stocks.js file in the static folder and then used a <script> tag in my index.html. This allows me to remove the require('stocks.js'), and avoids the webpack related error since stocks.js will be made available before I'm using it in my VueJS bundled application.

Maybe this will help someone with a similar issue regarding using stocks.js in webpack dependent projects.

from stocks.js.

asemoon avatar asemoon commented on June 8, 2024

please add this to the ReadMe file it took me 30 minutes to figure out you have to do require('stocks.js') not require('stocks')

from stocks.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.