mongo 刪除節點
在AWS中部署生產Web應用程序的經驗教訓 (Lessons learned deploying a production web application in AWS)
背景 (Background)
This is not a code-based tutorial. It consists of all the things I wish I knew before I started the project and the steps I took that worked out pretty well. It follows the development of a production Node.js web application created with the Express framework that was deployed onto Amazon Web Services (AWS).
這不是基于代碼的教程。 它包括我在開始該項目之前希望了解的所有內容,以及我所采取的步驟,這些步驟都很好地完成了。 它遵循使用Express框架創建的生產Node.js Web應用程序的開發,該應用程序已部署到Amazon Web Services(AWS)上。
The full-scale tutorial is available here.
完整的教程可在此處獲得 。
制定計劃至關重要 (Developing a plan is crucial)
There are entire books about developing plans, so I’m not going to elaborate upon that here. Just have one, whatever it is.
整本書中都有關于制定計劃的書,因此在這里我不再贅述。 不管是什么,只要一個。
你永遠不會分配足夠的時間 (You never allot yourself enough time)
It didn’t seem to matter how simple or complex a task was. I never estimated the time a given task would take correctly. I imagine that as I do more of these, I will get better at estimating time frames.
看起來任務多么簡單或復雜并不重要。 我從未估計過給定任務所需的時間。 我想象隨著我做更多的事情,我將在估計時間范圍方面變得更好。
Something that can help with this is to set a realistic timeline that gives yourself enough buffer to adjust if necessary.
可以幫助您解決此問題的方法是設置一個現實的時間表,為您提供足夠的緩沖以在必要時進行調整。
從一開始就部署到服務器 (Deploy to the Server from the very beginning)
There’s an old dev saying that goes something like, “Always develop in an environment that is the same as your deployment environment.” This is why things like Virtual Environments exist. This is sage advice.
有一個古老的開發人員說:“始終在與部署環境相同的環境中進行開發。” 這就是為什么存在諸如虛擬環境之類的原因。 這是圣人的建議。
Right now, it’s so easy to just grab a generator (such as express generator or create-react-app), yarn install
and write all our code locally. This is great for a development, but what I learned on the last project is if you wait for deployment until the end, you’ll be surprised at the number of things that “should work” but don’t.
現在,只需抓住一個生成器(例如express generator或create-react-app ), yarn install
并在本地編寫我們的所有代碼都非常容易。 這對于開發非常有用,但是我在上一個項目中了解到的是,如果您等待部署直到最后,您會驚訝于“應該起作用”但不起作用的事物數量。
For this project I chose to incrementally deploy the application while I built it. It made sure that what I was building was going to work on the environment I would be deploying it on. Also, it saved a ton of time when the actual deployment time came.
對于這個項目,我選擇在構建應用程序時逐步部署該應用程序。 它確保了我正在構建的內容可以在要部署它的環境上工作。 此外,當實際部署時間到來時,它節省了大量時間。
與客戶溝通是關鍵 (Communication with the client is key)
I do most of my work by myself, so sometimes I find that a solution I’ve come up with doesn’t always make sense to the person who is going to use it. It’s incredibly important to get client buy-in. In fact, if you can manage to get them to come up with the idea, they will love it, I promise. Nothing makes a human happier than being listened to.
我大部分工作都是由我自己完成的,因此有時我發現我想出的解決方案并不總是對打算使用它的人有意義。 獲得客戶的認可非常重要。 事實上,我保證,如果您能夠設法讓他們提出這個想法,他們會喜歡的 。 沒有什么比聆聽使人快樂。
除了-我很幸運有一個非常好的客戶 (Aside - I got lucky with a REALLY good client)
This isn’t so much a lesson, so much as a reminder of how important it is that you pick your clients. I know this sounds impossible, and frankly when you’re first starting out, it is very hard to be picky about your jobs. However, I’ve accepted jobs before that turned into nightmares because I ignored the signs.
這不是一堂課,而是提醒您選擇客戶是多么重要。 我知道這聽起來是不可能的,坦率地說,當您剛開始工作時,很難對您的工作保持挑剔。 但是,在那之前,我已經接受了工作,變成了噩夢,因為我忽略了這些跡象。
Phrases like, “We need it ASAP” are a good indicator that the client is going to undervalue your worth.
諸如“我們需要它”之類的短語很好地表明了客戶將低估您的價值。
計劃失敗 (Plan for Failure)
I think sometimes we look at established apps like Facebook or Instagram and try to reach that goal with our Version 1.0 apps. This is impossible for two reasons:
我認為有時我們會查看Facebook或Instagram等已建立的應用程序,并嘗試通過我們的1.0版應用程序實現這一目標。 這是不可能的,原因有兩個:
- Proper growth of an app requires user input. Do you think Instagram had a plan to add stories in their 1.0 version? Of course not, they waited for Snapchat to do it first then copied them. ? 應用的正確增長需要用戶輸入。 您是否認為Instagram有計劃在其1.0版本中添加故事? 當然不是,他們等著Snapchat先做后復制。 ?
- If you wait until it’s perfect, it will never be finished. 如果您等到完美為止,它將永遠不會完成。
What I’m getting at is, do the best you can, but don’t get hung up on writing the perfect function. Make it work, and improve as you go.
我正在做的是,盡力而為,但不要掛在編寫完美的函數上。 使它起作用,并隨著您的發展而不斷改進。
Also, knowing that things will fail, make sure you are handling your errors correctly. The user needs to know if something goes wrong, even if they can’t do anything about it.
另外,知道一切都會失敗,請確保正確處理錯誤。 用戶需要知道是否出了什么問題,即使他們對此無能為力。
用戶測試的重要性 (The Importance of User Testing)
Do NOT send the client a link and say, “Go check this out,” if you are planning on leaving your computer anytime soon. I made the mistake of doing that and then was bombarded with messages within an hour, while I was trying to eat lunch. Unless of course you enjoy bugs with your sushi.Not always the solution.
如果您打算盡快離開計算機,請不要向客戶發送鏈接并說“去檢查一下”。 我犯了一個錯誤,然后在嘗試吃午餐的一個小時內被消息轟炸。 除非您當然喜歡壽司中的蟲子,但并非總是解決方案。
It may be obvious to you, but that doesn’t mean it’s obvious to anyone else. A lot of the little things that became bugs were because of a bad UX or UI. I took for granted that I knew exactly what needed to happen because I wrote the thing. I’m not saying that you can plan for everything, but be aware that you will need to adjust some of your layouts so everyone will know what you want them to do.
這對您可能很明顯,但這并不意味著對其他任何人都顯而易見。 變成錯誤的許多小問題是由于不良的UX或UI。 我想當然了,因為我寫了東西,所以我確切地知道需要做什么。 我并不是說您可以為所有事情做計劃,但是要注意,您將需要調整一些布局,以便每個人都知道您想要它們做什么。
I originally only allotted two weeks for beta testing. One to test, one to fix. This is not enough time. I ended up having a week of beta testing part one, a week of cleanup, and then another week of beta testing, followed by another week of cleanup.
我最初只分配了兩個星期的Beta測試時間。 一個要測試,一個要修復。 時間不夠。 我最后進行了一周的beta測試(第一部分),一周的清理,然后進行了一周的beta測試,然后又進行了一周的清理。
不要依附于產品 (Don’t get attached to the product)
This ideal is driven by my graphic design background. If we stick to a design because we really like it, we will ignore all user feedback (what really matters) and never change. It is the same with building an app.
這個理想是由我的圖形設計背景決定的。 如果我們堅持設計,因為我們真的很喜歡它,那么我們將忽略所有用戶反饋(真正重要的信息),并且永遠不會改變。 與構建應用程序相同。
Creating something out of nothing is, as the name implies, a creative act. You are making a lot of decisions about how you think a user will interact with the thing you are building. Don’t think you know better than the user — you don’t.
顧名思義,一無所有是創造力。 您正在做出許多有關用戶如何與正在構建的事物進行交互的決定。 不要以為您比用戶更了解-您沒有。
玩得開心 (Have fun)
There’s no reason why you can’t enjoy the thing you’re doing. That’s not to say it won’t be incredibly frustrating, but try and enjoy it as much as you can.
沒有理由讓您無法享受正在做的事情。 這并不是說它不會令人難以置信的沮喪,而是嘗試并盡可能多地享受它。
學習一些東西 (Learn something)
Deadlines are deadlines, but if you can incorporate one new thing into your stack, do it. You’ll be a much better developer afterwards.
截止日期是截止日期,但是如果您可以將新事物集成到堆棧中,請執行截止日期。 之后,您將成為更好的開發人員。
My biggest challenge for this project was AWS. I spent a ton of hours getting to know AWS. But now I have that notch on my belt for the next job. It would have been so easy to just deploy it to Heroku and call it a day, but that’s not the best option for a number of reasons.
這個項目的最大挑戰是AWS。 我花了很多小時來了解AWS。 但是現在,我可以勝任下一份工作了。 只需將其部署到Heroku并每天進行調用就很容易了,但是由于多種原因,這并不是最佳選擇。
推動最有價值球員 (Push for that MVP)
At the time of this writing, I still have about 20 open issues on the project. Expecting to finish every single item for version 1.0 is unrealistic. Always push for the minimum viable product (MVP) initially. Prioritization is key to determining what really matters in a project.
在撰寫本文時,我在該項目上仍有大約20個未解決的問題。 期望完成1.0版的每個項目都是不現實的。 始終始終爭取最低可行產品(MVP)。 優先級是確定項目中真正重要的關鍵。
Example: One of the open issues I have is that the padding is not right on the navigation. Is this a breaking issue? No. Can it wait until all the core features are done to fix it? Yes.
示例:我有一個未解決的問題,就是導航區上的填充不正確。 這是一個重大問題嗎? 不可以。它可以等到所有核心功能都完成后再修復嗎? 是。
So, I haven’t fixed it yet. However, I’ve expressed this to the client and they are OK with it.
所以,我還沒有解決。 但是,我已經向客戶表示了這一點,他們對此表示滿意。
下次我會做的事情有所不同 (Things I will do differently next time)
單元測試 (Unit Testing)
I hadn’t done anything with testing before this project, so I didn’t do unit testing for this project. Huge mistake. I ended up having to integrate tests after I had already built the thing.
在這個項目之前,我沒有做任何測試,因此我沒有為這個項目做單元測試。 巨大的錯誤。 在構建完東西之后,我最終不得不集成測試。
Unit testing helps with the following:
單元測試有助于以下方面:
Every time I added a new feature or changed something, I had to test everything manually. Not good.
每次添加新功能或更改某些功能時,都必須手動測試所有內容。 不好。
- It maintains a level of functionality and also allows you to realize some shortcomings of your code. Purposely writing tests that will fail helps identity issues within the code. 它保持一定的功能水平,還使您能夠意識到代碼的某些缺點。 故意編寫將失敗的測試有助于代碼中的身份問題。
I highly suggest the TDD course by FunFunFunction to get started.
我強烈建議您使用FunFunFunction開發 TDD課程。
Small aside: If you use the express generator, it doesn’t export the server.
撇開一點:如果使用express生成器,它不會導出服務器。
If you want to test the server with Mocha, you have to export it at the end of the bin/www
file.module.exports = server;
如果要使用Mocha測試服務器,則必須將其導出到bin/www
file.modulesexports = server的末尾。
從一開始就更深入地了解每個功能 (Get a more in depth look at each feature from the beginning)
I made a list of all the features when I started, but I didn’t do a deep dive up front to see how I was actually going to implement them. If I had done this, I probably could have estimated my time better.
我在開始時就列出了所有功能,但并沒有深入了解我實際上將如何實現它們。 如果這樣做,我可能可以更好地估計自己的時間。
我學到的小知識 (Little things I learned)
您可以使用HTML輸入訪問相機-歡迎使用2018 (You can access the camera with an HTML input — Welcome to 2018)
However, this doesn’t work over non-secure pages in iOS.
但是,這不適用于iOS中的非安全頁面。
文件上傳和調整大小很麻煩 (File upload and resize is a pain)
The tutorial I went through showed the method for saving locally, however I wanted to leverage AWS S3. To be honest, the method I have setup is not ideal, so hopefully I can address this better in the future.
我閱讀的教程展示了本地保存的方法,但是我想利用AWS S3。 老實說,我設置的方法并不理想,因此希望以后可以更好地解決此問題。
如果您是新帳戶,AWS不允許您創建SSL證書 (AWS doesn’t let you create SSL Certificates if you are a new account)
As it turns out, AWS is pretty picky about new accounts. The customer service rep said it was to prevent new accounts from racking up huge bills, which I guess makes sense. Either way it’s pretty annoying when you are trying to launch an app and you can’t get your SSL Cert sorted.
事實證明,AWS對新帳戶非常挑剔。 客戶服務代表說,這是為了防止新帳戶積累大量賬單,我認為這是有道理的。 無論哪種方式,當您嘗試啟動應用程序并且無法對SSL證書進行排序時,這都很煩人。
Side note: if you use AWS for hosting, their certificate manager is amazingly easy.
旁注:如果您使用AWS進行托管,則其證書管理器非常簡單。
Mongo數據庫托管 (Mongo Database hosting)
I chose mLab to host my mongo database for a number of reasons:
由于多種原因,我選擇了mLab來托管我的mongo數據庫:
- I wanted backups without having to handle backups. mLab does that for you. 我想要備份而不必處理備份。 mLab為您做到了。
- I didn’t want to spend a ton of money (or rather I didn’t want my client to spend a ton of money). They cost $10 per gigabyte. 我不想花很多錢(或者我不想我的客戶花很多錢)。 每GB成本為10美元。
- Also, they allow hosting on AWS. So in my mind that will be faster. I doubt it, but it’s the thought that counts, right? 此外,它們允許在AWS上托管。 所以在我看來,這會更快。 我對此表示懷疑,但這是很重要的想法,對嗎?
更漂亮 (Prettier)
Prettier is a life saver. However, it often fights with my ESLint. For one thing, it always removes my parentheses around single param functions. Meaning: (var) => {}
更漂亮可以節省生命。 但是,它經常與我的ESLint沖突。 一方面,它總是消除單個參數函數的括號。 含義: (var) => {}
vs
與
var => {}
var => {}
Illustrator不斷創建1000 x 1001像素的圖標 (Illustrator kept creating favicons that were 1000 x 1001 pixels)
Turns out if you don’t arrange the art boards to the pixel grid, it will throw it off. Using the auto arrange art boards feature will solve that issue. More info here.
事實證明,如果不將畫板布置在像素網格上,它將被丟棄。 使用自動排列畫板功能可以解決該問題。 更多信息在這里 。
為失敗而努力很重要 (Building for failure is important)
The further along I got with other people using the app, the more I had to adjust my database and views. That meant breaking things that used to work.
我與其他人使用該應用程序的距離越遠,我調整數據庫和視圖所需的時間就越多。 這意味著要打破曾經起作用的東西。
It’s hard to plan for everything but I got into the habit of expecting there to be no data and handling it.
很難為所有事情做計劃,但是我養成了期待沒有數據并處理它的習慣。
Example: I changed how I was storing images. It was in a field called ‘documentation’. When I switched how I was storing it I also changed it in the view, but that broke the older entries.
示例:我更改了存儲圖像的方式。 它位于一個稱為“文檔”的字段中。 當我切換存儲方式時,我也在視圖中進行了更改,但這打破了舊的條目。
I solved this by first checking to see if there was anything at all. And if there was, run some logic.
我通過首先檢查是否有任何東西來解決此問題。 如果有,請運行一些邏輯。
摘要 (Summary)
This isn’t everything I learned, but hopefully some of it is useful to someone. If you have questions, hit me up.
這不是我學到的一切,但希望其中一些對某人有用。 如果您有任何疑問,請打我。
I can’t share the code for this project due to it being for a client. However, I’m happy to expand on any of the things in this article if you have questions.
我無法共享此項目的代碼,因為它是針對客戶的。 但是,如果您有任何疑問,我很樂意擴展本文中的任何內容。
Happy Coding!
科丁快樂 !
翻譯自: https://www.freecodecamp.org/news/deploying-a-production-node-express-mongo-app-to-aws-a-reflection-8982894289c6/
mongo 刪除節點