Ok, I got the issue,
According to the docs of Web3-docs-link (web3), setProvider() is used to change the provider of the web3, if you are setting the provider for the first time you have to use in this way:
var Web3 = require('web3');
var web3 = new Web3('http://localhost:8545');
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:...