Calling Node.js methods through Mac terminal

I am beginner to back end developer languages like Node.js and I want to practice by learning how to run Node.js files and their methods. I've decided to try scrapers to apply knowledge so forgive my lack of skills.

I've got Node installed on my Mac and I want to run this library:

I've followed their instructions, installed their library using 'npm kijiji-scraper' and ran Ad.Get() and the terminal showed:

Users-MacBook-Air:~ userOne$ Ad.Get() >

I entered the method below:

Users-MacBook-Air:~ userOne$ Ad.Get()

(url[, callback])

And got no errors but nothing outputted in the terminal.

I tried entering a URL but got an error message:

Users-MacBook-Air:~ userOne$ Ad.Get() -bash: syntax error near unexpected token `'

Unfortunately, I have no idea how to call methods. Are there any good beginner guides or help you could give? I tried passing in a URL into Ad.Get() because I assumed that would work but nothing was outputted onto the terminal.

Any tips? I know this question seems totally lazy and unprofessional but I've tried reading some guides and I think this specific scenario requires a versatile knowledge of node.

1 answer

  • answered 2018-07-07 23:10 Karamell

    You're not supposed to execute that from the terminal.

    Instead, you should create a file, e.g. myScaper.js.

    In this file, write this code;

    const {Ad} = require("kijiji-scraper");
    Ad.get('').then((result) => {

    Then run this by doing node myScaper.js in the terminal being in the folder that you ran npm i kijiji-scraper in.

    This should get you started.