NodeJs beginner learning notes exercise project outline

Source: Internet
Author: User
NodeJs beginner learning notes exercise Project Outline Introduction NodeJs's personal opinion exercise Project Outline Introduction after all is not the first time to learn programming, So I thought about something fun, after turning around the node. js official website and CnodeJs, I felt a little bit slow and recorded the learning process... syntaxHighlighter. all (); NodeJs beginner learning notes exercise project outline
Introduction
NodeJs's personal opinion
Exercise project outline
Introduction
After all, it was not the first time I learned programming. So I thought about something fun. After I went to the official node. js website and CnodeJs and turned around, I felt a little bit better, record the learning process as an archive or make a contribution to nodejs.
NodeJs's personal opinion
The most typical example of NodeJs is the http server. It is also the most mature nodejs Learning case. in the course of studying nodejs, I found that there are few materials that Nodejs can deal with more mobile clients. In my opinion, the asynchronous IO model of nodejs is very suitable for mobile clients, for example, when uploading an image at a very slow speed on the mobile Internet, the server may not wait until one of your images is uploaded. if asynchronous I/O is used here, the server only needs to accept Image Upload, and nothing else needs to be done. the above is my humble opinion on the application scope of nodejs.
Therefore, this exercise project is simply modeled on the popular Instagram
Exercise Project Planning
After all, the purpose here is not to completely imitate Instagram, so the design is very casual.
Let's look at the main functions of Instagram.
Client
Image Retrieval
Upload images
Server playback
Receive images
Save image
I have simplified the Instagram function in an all-out-of-the-box manner.
1. The client can upload a photo.
2. The server can receive image uploads.
The first exercise project is to complete the above two objectives.
Client
After two hours of coding, I finally got a prototype and packed it into an apk which can be installed on my mobile phone. This is the node. js community, if you are interested in the client, you can follow my blog. My blog will record the development process of the client at a later time.
Server
Nodejs + express 3.x
This time, the server is relatively simple to do. To put it bluntly, it is only necessary to support file upload. It is very simple to implement it with express.
Fragment 1:
// Obtain the temporary path of the file
Var tmp_path = req. files. thumbnail. path;
Here we will talk about the differences between Windows and linux. the file system in win is not like that in linux, all paths can be completed based on/xxx/xx. Therefore, if you change the default file upload directory in express in win, you 'd better fill in the absolute path.
Fragment 2
// Move the temporary file to the target folder
'Fs. rename (temppath, targetpath, function (err) {if (err) throw err;
// Delete a temporary file
Fs. unlink (temp_path, function () {if (err) throw err ;});});'
For more details, see Source Code 47-54 in app. js.
That's all? Of course it won't happen. The next step is to make fun of it. But let me take a rest for the time being. If you are interested, continue to pay attention to it. But don't expect it to be too high. After all, I just want to be interested.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.