Chocochips Software Solutions (OPC) Pvt. Ltd.


Points to Remember in Node.js , JavaScript and HTML

by Vibhu Tewary on 2016-11-18 12.05 Hrs

1. HTML

Close <p> with </p> wherever used. Sometimes, if you save the page as html and don't have a </p>, the brower adds the </p> therefore changing the intended formatiing of the page. This can change a div's minimum height, and the height of it won't reduce beyond <p> height even after applying a style with heiht property.

2. Node.js (Busboy)

You can check if file is not selected while uploading in busboy from:

  if(!filename)
  return;


3. Node.js (Express)

While using app.redirect (which redirects to a route), the destination should have GET (router.get).

4. Node.js (Javascript)

Remember there are asynchronous functions in javascript and node.js. Meaning code is processed in callbacks.

5. Node.js (Pagination)

In pagination, the get value of zero crashes the server. Check with "if" statement for lower and upper value before running the value against a database (skip 0-1, will crash server, when page is entered as 0 (and lesser)).

6. Node.js (HTML)

input type of text should have name and not id for it to be read in POST route

7. Node.js (Express)

If redirect is not the last peice of code in an if statement, it should have return; Otherwise even after redirect, following code gets executed.

8. Mongodb (Node.js)

While sorting in Mongodb, you have to use parseInt in Javascript to store non-quotes vaue of integer. Sorting will still be incorrect if the field has both number in numeric form and numbers in string form. All the values have to be numberic to do a number sort.

9. Node.js (Express)

The res.render in node renders the ejs contents, but on page refresh, the url with .js contents will get executed again, for example, it will send emails again if it was so in the js file.

10. Node.js (Mongodb)

If find by _id, where passed string is invalid (longer etc.), the find method will crash web server..

11. Node.js (Express)

You can't access a route which handles a POST type by entering the route url in the address tab

12. Node.js (Mongodb)

Check if an ObjectId in mongodb is valid using try and catch. Otherwise server crashes if you pass an invalid id string to argument as can be the case in GET method.

13. Node.js (Express)

The render method should have "/" in start of view urls.

14. HTML Emails

HTML emails require http:// prefix for their urls to display and work.

15. Using JavaScript Date().getTime() to convert milliseconds to local time

Date().getTime() always returns same milliseconds if the system time is the correct local time for any timezone. It will change if the system time is changed.


To leave a comment, use our "Contact" page, with what you have in mind. We'll post it here if its moderator approved.