Why did the US abandon the Chinese Nationalists to Mao but then turn and fight the North Korean Communists just a few years later. China with its vast amount of natural resources and ~500 million people around that time seems like it would be a much more important ally compared to Korea's ~22 million people and small land size. I'm reading The Rising Sun by John Toland and it touches some on Chiang Kai-Shek being more interested in fighting the Chinese Communists rather than Japan along with the corruption in the nationalist government.
Apples and oranges.
China was an independent nation that used to have Korea as a tributary state until the late 1800's when Japan broke the two apart. Korea then became a Japanese colony from 1895/1910 (depending on your point of view - officially 1910, but the beginning of it was during the First Sino-Japanese War) and only became free upon the collapse of the Japanese Empire. Even then, the fate of Korea from 1945 until 1953 was up in the air:
But to your question, I think it's better to look at the Korean War as an extension of the Chinese Civil War.
The backbone of the North Korean People's Army was made up of Korean communists who had volunteered to fight in China against the Nationalists.
Once the war turned against the North in September 1950, the Chinese People's Volunteer Army began marching towards North Korea, entering the country in mid October, and by December 1950, it was no longer a war against the KPA, but against the Chinese PVA.
The Armistice agreement was signed on behalf of China and North Korea by a North Korean and on behalf of the United Nations Command by an American, but not a South Korean.
/u/GroovyGoulash makes some good points on the loss of China, but I'd like to add a bit to it. There were two groups at play in the US government - the pro China faction and the not pro-China/anti-communst faction. The pro-China folks, known as the "China Hands," were made up of people who had ties to China - children of missionaries, people who had done business there, and the such. The China Hands were practical - they recognized the Chinese Communists appeal and power and the Nationalists corruption and they saw that the Nationalists were on the way out. They pushed for the US to make inroads with the Communists because they knew that they might very well win the war. The other side wanted to see Chiang Kei-shek and the Nationalists win and they used their power to undermine the China Hands. They had some of the Foreign Service officers removed from their posts and they pushed the anti-communist agenda. They supplied the Nationalists with weapons which continuously fell into the Communist's hands - I can't remember where I read it, but I believe that Mao said that the US aid/Nationalist army was his best supplier. Once the China Hands were marginalized, there was no one in the government looking to work with the Communists who finally won the war in 1949. The next 8 months would be critical for the Korean War.
After winning the Chinese Civil War, Mao went to Moscow in December of 1949 to be honored and recognized by Stalin. In reality, he was snubbed and humiliated by the Soviets and left with a bitter taste in his mouth. At the same Kim Il-sung was chomping at the bit to take over the South. Kim went to Moscow in March/April of 1950 (after having visited there in 1949 as well) and finally got approval from Stalin to attack the South. With this approval came material support and promised air support (which never materialized to the degree that was promised), but Kim had to get the Chinese on board for manpower. By telling the Chinese that Stalin was on board, they agreed to help if it became necessary. Kim promised that the war would be quick.
Why do I see the Korean War as an extension of the Chinese Civil War?
MacArthur and the anti-communist forces in Washington. By supplying the Chinese Nationalists, they alienated themselves from the eventual victors, the communists. MacArthur was vocal about wanting to defeat Communism and was not shy about his desire to widen the Korean conflict into a full blown war with China to defeat the Communists and reinstall Chiang Kei-shek and the Nationalists in Beijing.
Mao and his anti-American viewpoint. During discussions with his military commanders, one of their fears was the use of nuclear weapons. Mao was not concerned about this because China was so large and so populous with the majority of people living spread out in the country that nuclear weapons would be of minimal value against China. His goal was to deliver a stinging defeat to America to force them, at a minimum, out of mainland Asia, but if he could get them out of Japan too, all the better.
US military actions. At the outset of the Korean War, the US Navy stationed ships between Taiwan and the mainland to prevent the Chinese from taking advantage of the situation and attacking Taiwan. This was before the Chinese got involved in Korea, but it shows the concerns of the US; the Communists taking advantage of US attention elsewhere or Chiang Kei-shek taking advantage to re-invade the mainland.
Why did the US not get involved in China but they did in Korea?
China was a civil war that had started before WWII. Korea was a UN mandate that had turned into separate countries due to the Cold War. US support in China was limited to advisors and weapons. During the Civil War, there were no US casualties. In Korea, US advisors were killed or captured during the opening round which was an attack of one (arguably) sovereign nation against another (less arguably) sovereign nation. Finally, while the US did get involved in Korea, it was officially the UN that got involved and while the US did the heavy lifting, there were soldiers and non-combat support from dozens of other countries all around the world. To compare China and Korea and foreign intervention is like comparing apples to oranges.
The "loss of China" (as it was known) was a shock to the Truman Administration, who (along with the prior Roosevelt Administration) had believed the Chinese Nationalists to be much more capable and functional than they eventually proved themselves to be.
China had been viewed as an important ally during and after World War II - China was one of Roosevelt's "Big Four" powers (also known as the "Four Policemen") and was a founding, permanent member of the UN Security Council. The "loss of China" seemed to validate anti-communists in the U.S. government, some of whom accused the Truman Administration of being "too soft" on communism. This led to a harsher stance on stopping the spread of communism in Asia.
In short, it's not so much that the U.S. viewed Korea as more important than China, it's that they were surprised by the Communist victory in China and were determined not to let it happen again.