How can users buy nodes they can create? I want users to pay 5$ for each node they want to create.

They should be able choose, on registration, to pay from 1 to 400 nodes and more later if needed. The nodes should unpublish after a year with an option for a user to renew. Another option is to have multiple roles for purchase, each with a predefined number of nodes he can create, and let users choose the role on registration. 

Is this possible?
There's already a Commerce subproject called Commerce Node Checkout that does node publish purchasing with the option for expiration. 


  Integrate with Commerce in order to allow you to charge users to
  create nodes. It is possible to have multiple different product
  offerings for each node type, so the user can pick the product they
  want to purchase when creating the node. An example use-case would be
  a classifieds site that charges people to post listings.


It's purchase process is on demand, rather than purchasing a credit quota, so you might have to look at something different to base your project on depending on how important the quota functionality is.

An alternative role-based approach would be the Commerce License Roles submodule and something like the Node Limit module to setup your quota-per-role requirement. You'd also have to find a node expiration solution (e.g. Node Expire) as well.