-
Notifications
You must be signed in to change notification settings - Fork 0
/
i-tired-nodejs-and-i-like-it.html
159 lines (139 loc) · 12 KB
/
i-tired-nodejs-and-i-like-it.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="http://www.emadmokhtar.com/theme/stylesheet/style.min.css">
<link rel="stylesheet" type="text/css" href="http://www.emadmokhtar.com/theme/stylesheet/pygments.min.css">
<link rel="stylesheet" type="text/css" href="http://www.emadmokhtar.com/theme/stylesheet/font-awesome.min.css">
<link href="http://www.emadmokhtar.com/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Emad Mokhtar's Framework Atom">
<link href="http://www.emadmokhtar.com/feeds/all.rss.xml" type="application/rss+xml" rel="alternate" title="Emad Mokhtar's Framework RSS">
<link rel="shortcut icon" href="http://www.emadmokhtar.com/images/favicon.ico" type="image/x-icon">
<link rel="icon" href="http://www.emadmokhtar.com/images/favicon.ico" type="image/x-icon">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="" />
<meta name="author" content="Emad Mokhtar" />
<meta name="description" content="Photo by Austin Chan on Unsplash I had a chance to try Node.js framework last month; I decided to build REST APIs using Node.js and express.js. Regularly I'm using JavaScript in my daily work besides using Django to build Web Applications, but many times I need to develop a front-end feature, This when I need to use JavaScript. I'm always using JavaScript to write front-end logic, but I never wrote back-end logic using it. I took the challenge to develop a simple REST APIs using express.js." />
<meta name="keywords" content="Python">
<meta property="og:site_name" content="Emad Mokhtar's Framework"/>
<meta property="og:title" content="I tired Nodejs and I like it"/>
<meta property="og:description" content="Photo by Austin Chan on Unsplash I had a chance to try Node.js framework last month; I decided to build REST APIs using Node.js and express.js. Regularly I'm using JavaScript in my daily work besides using Django to build Web Applications, but many times I need to develop a front-end feature, This when I need to use JavaScript. I'm always using JavaScript to write front-end logic, but I never wrote back-end logic using it. I took the challenge to develop a simple REST APIs using express.js."/>
<meta property="og:locale" content="en_US"/>
<meta property="og:url" content="http://www.emadmokhtar.com/i-tired-nodejs-and-i-like-it.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2018-12-31 12:00:00+03:00"/>
<meta property="article:modified_time" content=""/>
<meta property="article:author" content="http://www.emadmokhtar.com/author/emad-mokhtar.html">
<meta property="article:section" content="python, nodejs"/>
<meta property="article:tag" content="Python"/>
<meta property="og:image" content="http://www.emadmokhtar.com/images/profile.jpg">
<title>Emad Mokhtar's Framework – I tired Nodejs and I like it</title>
</head>
<body>
<aside>
<div>
<a href="http://www.emadmokhtar.com">
<img src="http://www.emadmokhtar.com/images/profile.jpg" alt="" title="">
</a>
<h1><a href="http://www.emadmokhtar.com"></a></h1>
<p>Geek developer who's in search of code perfection.</p>
<nav>
<ul class="list">
<li><a href="http://www.emadmokhtar.com">Blog</a></li>
<li><a href="http://www.emadmokhtar.com/pages/podcasts.html#podcasts">Podcasts</a></li>
<li><a href="http://www.emadmokhtar.com/pages/projects.html#projects">Projects</a></li>
<li><a href="https://emadmokhtar.github.io/resume" target="_blank">Resume</a></li>
</ul>
</nav>
<ul class="social">
<li><a class="sc-envelope-o" href="mailto:emad@emadmokhtar.com" target="_blank"><i class="fa fa-envelope-o"></i></a></li>
<li><a class="sc-github" href="https://www.github.com/EmadMokhtar" target="_blank"><i class="fa fa-github"></i></a></li>
<li><a class="sc-linkedin" href="https://www.linkedin.com/in/emadmokhtar/" target="_blank"><i class="fa fa-linkedin"></i></a></li>
<li><a class="sc-stack-overflow" href="http://stackoverflow.com/users/373051/emad-mokhtar" target="_blank"><i class="fa fa-stack-overflow"></i></a></li>
<li><a class="sc-facebook" href="https://www.facebook.com/emadmokhtarframework/" target="_blank"><i class="fa fa-facebook"></i></a></li>
<li><a class="sc-twitter" href="https://twitter.com/emadmokhtar" target="_blank"><i class="fa fa-twitter"></i></a></li>
</ul>
</div>
</aside>
<main>
<nav>
<a href="http://www.emadmokhtar.com">Home</a>
<a href="https://emadmokhtar.github.io/resume">Resume</a>
<a href="http://www.emadmokhtar.com/feeds/all.atom.xml">Atom</a>
<a href="http://www.emadmokhtar.com/feeds/all.rss.xml">RSS</a>
</nav>
<article>
<header>
<h1 id="i-tired-nodejs-and-i-like-it">I tired Nodejs and I like it</h1>
<p>Posted on Mon 31 December 2018 in <a href="http://www.emadmokhtar.com/category/python-nodejs.html">python, nodejs</a> <b>Read in 3 min.</b></p>
</header>
<div>
<p><img alt="The Sign" src="http://www.emadmokhtar.com/images/austin-chan-275638-unsplash.jpg">
Photo by Austin Chan on Unsplash</p>
<p>I had a chance to try Node.js framework last month; I decided to build REST APIs using <a href="https://nodejs.org/en/">Node.js</a> and <a href="https://expressjs.com/">express.js</a>. Regularly I'm using JavaScript in my daily work besides using <a href="https://www.djangoproject.com/">Django</a> to build Web Applications, but many times I need to develop a front-end feature, This when I need to use JavaScript. I'm always using JavaScript to write front-end logic, but I never wrote back-end logic using it. I took the challenge to develop a simple REST APIs using <a href="https://expressjs.com/">express.js</a>.</p>
<iframe src="https://giphy.com/embed/d4zHnLjdy48Cc" width="480" height="350" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
<p><strong>Development environment</strong></p>
<p>To start developing, I need to get my machine ready, so I installed <a href="https://nodejs.org/en/">node.js</a> via Homebrew (I'm a macOS user), it is quite easy, and node.js installation comes with <a href="https://www.npmjs.com/">npm</a> "npm is a package manager for node.js it is like <a href="https://pypi.org/">pypi</a> or pip for Python". I used <a href="https://code.visualstudio.com/">Visual Studio Code</a> as a text editor. Now I'm ready to go 💪🏻.</p>
<p><strong>What I've learned?</strong></p>
<p>While building the REST APIs, I've learned many things, mainly that I'm experiencing the new development stack. Let's see the parts I've learned.</p>
<p><strong>Node.js</strong></p>
<p><a href="https://nodejs.org/en/">Node.js</a> is a back-end engine; it is using Google Chrome V8 JavaScript engine to run JavaScript code on your machine instead of a browser. Node is not a language it is an engine.</p>
<p><strong>Express.js</strong></p>
<p><a href="https://expressjs.com/">Express.js</a> is a web framework that uses Node.js; it is a minimalist web framework "micro-framework" that receives requests and replies with responses, micro-framework means it doesn't have ORM, template engine, etc. You can feel it is like <a href="http://flask.pocoo.org/">Python Flask Framework</a>.</p>
<p><strong>ORM</strong></p>
<p>I tried to build my models using <a href="http://docs.sequelizejs.com/">sequelize JS</a> as I'm more familiar with PostgreSQL DB engine, but it turns to be so tricky to implement my feature using RDBMS system. I switched ORM to <a href="https://mongoosejs.com/">Mongoose JS</a>, and my database engine to <a href="https://www.mongodb.com/">MongoDB</a>. I was wrong from the beginning, but after switching to <a href="https://www.mongodb.com/">MongoDB</a>, it is much easier to implement the feature, as it is a preferred database engine in Node.js community.</p>
<p><strong>Asynchronous Programming 🤔</strong></p>
<p>Getting used to the nature of <a href="https://developers.google.com/web/fundamentals/primers/promises">JavaScript asynchronous "Promises"</a> was a big challenge for me, I'm used to synchronous programming; thus it was a big paradigm shift 🤯. On a daily basis, I'm using <a href="https://www.djangoproject.com/">Django</a>, and it is not asynchronous by default <a href="https://www.aeracode.org/2018/06/04/django-async-roadmap/">"there is a roadmap for Django to be Async"</a>. <a href="https://docs.python.org/3.5/library/asyncio.html">Python has asynchronous programming since version 3.5</a>, but frameworks need to adapt it to become asynchronous as well, like <a href="https://github.com/ross/requests-futures">requests-future</a>.</p>
<p><strong>Final Thoughts 🧐</strong></p>
<p>I enjoyed using Node.js; the community is excellent, there is nothing you can't find a package for on NPM, it is such an active community, but what I don't like in the community is the quality of tutorials, most of the tutorials targeting starters or naive nodejs developers, yes we need tutorials for starters and naive nodejs developers, but what about the advanced tutorials.</p>
<p>The async programming challenge was an eye-opener for me; I need to dig deep in this way of programming especially in Python. I'm lucky that there is a video course on <a href="https://training.talkpython.fm/courses/explore_async_python/async-in-python-with-threading-and-multiprocessing">Talk Python training about asynchronous in Python</a>, and I think I will watch it.</p>
</div>
<div class="tag-cloud">
<p>
<a href="http://www.emadmokhtar.com/tag/python.html">Python</a>
</p>
</div>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'emadmokhtarsframework';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
</article>
<footer>
<p>© Emad Mokhtar </p>
<p>Built using <a href="http://getpelican.com" target="_blank">Pelican</a> - <a href="https://github.com/alexandrevicenzi/flex" target="_blank">Flex</a> theme by <a href="http://alexandrevicenzi.com" target="_blank">Alexandre Vicenzi</a></p> </footer>
</main>
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-11401860-2', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"name": "I tired Nodejs and I like it",
"headline": "I tired Nodejs and I like it",
"datePublished": "2018-12-31 12:00:00+03:00",
"dateModified": "",
"author": {
"@type": "Person",
"name": "Emad Mokhtar",
"url": "http://www.emadmokhtar.com/author/emad-mokhtar.html"
},
"image": "http://www.emadmokhtar.com/images/profile.jpg",
"url": "http://www.emadmokhtar.com/i-tired-nodejs-and-i-like-it.html",
"description": "Photo by Austin Chan on Unsplash I had a chance to try Node.js framework last month; I decided to build REST APIs using Node.js and express.js. Regularly I'm using JavaScript in my daily work besides using Django to build Web Applications, but many times I need to develop a front-end feature, This when I need to use JavaScript. I'm always using JavaScript to write front-end logic, but I never wrote back-end logic using it. I took the challenge to develop a simple REST APIs using express.js."
}
</script></body>
</html>