Delete All nodes of specific content type programmatically

This is mainly for deleting all testing data that you may have created using devel generate module or similar to it

If you have devel php installed in your drupal site you can directly run this is the browser or you may have to use it in the custom module 

I would recommend to use devel php module as it is much simpler and easy to use just make sure you don't have devel modules in your production environment and if you need to delete nodes in the production then just install devel to run this code and then uninstall


Below command will delete all basic page nodes so use is carefully 


$nids = \Drupal::entityQuery('node')->condition('type', page')->execute();

foreach ($nids as $key => $value) {

 $node[$key] = Node::load($value);