Răzvan Ilin

Full stack developer, casual traveler, amateur photographer

Using Sequelize with sqlite3 inside an Electron app

Introduction

A few months ago I ran into some problems when I tried to use Sequelize with sqlite3 inside an Electron app. Even though I installed everything properly, I was getting this error:

I was able to fix this using this website but it appears to be down now. I decided to write down the method here and also adding a bit more details on how to solve the problem.

Solution

  • Go to node_modules/sequelize/lib/dialects/connection-manager.js and identify the MODULE_NOT_FOUND error code. Log the error with a console.log(err) before the error is thrown.
  • Run the application and you will get a more detailed error:

{ Error: Cannot find module 'C:\Users\Razvan\Documents\devStuff\work\app\server\node_modules\sqlite3\lib\binding\electron-v1.3-win32-x64\node_sqlite3.node'

  • Note the electron-v1.3-win32-x64. You might have something different depending on the electron version you installed
  • cd node_modules/sqlite3 and then run the following:

  • --module_path replace with what you got from the MODULE_NOT_FOUND error
  • --target_platform win32, darwin or linux
  • --arch x64 or ia32
  • --target the version of electron you are using

 

If there are issues on Windows about MSB4019, check this issue https://github.com/brianmcd/contextify/issues/96

That’s all

By following the steps above I managed to make the configuration work on Windows and Mac. Hopefully this solves the problem for you too.

If you still encounter the problem, check this post on stackoverflow. It offers multiple approaches.

 

 

Productivity – Waking up early in the morning

You probably heard this before or read about it in a blog somewhere. A lot of people recommend waking up in the morning because it gives your day a boost. Well, I actually started doing this for the past 3 weeks and I will describe my experience about it. I won’t go over all the general benefits of waking up early because you can find that all over the Internet (I will leave some links at the end of the post).

Productivity

As the title says, productivity is one of the first motivation to wake up early in the morning. I work a lot on side projects and I am in need of some productive coding sessions when I’m home. Before, I used to go to sleep at around 1-2am and wake up just in time to make some food and get to work in time. I was procrastinating a lot during my evening coding sessions.

Typically I was “working” from 7-8pm to around 12am. I say “working” because half of the time I was scrolling through Facebook, watching Youtube videos and many other things that were not classified as productive.

So how does waking up early affect productivity? In my experience, I found out that after work, my brain was quite tired. My concentration levels were not as high as during the day and that’s why I found it so easy to drift into procrastination. At 5:30am in the morning I have an unpolluted fresh mind that helps me to be productive.

Longer Days

Theoretically, the days are not longer for me but if I wake up early, I’m under the impression that they actually are. Before, I used to sleep after 1am and wake up at around 7am. Now I go to sleep at 11pm and wake up around 5:30am. The amount of hours I sleep is about the same.

The problem is with not valuing the time properly. If I procrastinate I later thing that was all a waste of time when I could have been doing some more important stuff. Doing something I’m later grateful of, make my day more meaningful and I feel like I achieved a lot in a day hence the ‘length’ seems longer.

Quality time – Quiet time

I feel like I own the world when I wake up early! I feel super excited to get on with my things and enjoy the morning silence while doing so. Currently, I live in a shared flat and even if my flatmates are quiet, I still feel their presence in the house. Early morning? Nothing. And I like nothing, I like hearing the wind, the seagulls and people rushing with their cars in the distance.

My morning workspace

My morning workspace

The morning meal

Breakfast is the most important meal of the day because it gives you the much needed energy your brain and body needs for facing the day. I started eating a lot in the morning some time ago and I can confirm these benefits. When I get to work my mind is not thinking what will I have during lunch. I’m also really productive and do things much quicker and without mistakes.

Waking up early gives you enough time to pay attention on what you’re eating. You can cook something nice. I enjoy cooking and mornings are great for that.

Going to work prepared and in time

Before I started waking up early, I was rushing through making breakfast, having quick shower, ironing clothes and the running to work. Sometimes I was having just a tiny breakfast because I was running out of time. These things affect your mood. I found it better to have plenty of time in the morning to do all these and go to work relaxed.

Now that I wake up early I even have time to plan my day out. What exactly I will concentrate on at work, what will I do when I get back home, and so on. This saves me time later on and make me more confident.

Conclusion

Waking up early is one of the best decisions I took lately. I feel good that I finally have time to concentrate on my own projects and be productive at work at the same time. I want to experiment some more with this and I will give you updates through emails. One thing I want to try soon is to go running for about 20 minutes as soon as I wake up.

If you think your not productive enough during the day, I recommend you try waking up early and see if that boosts your productivity.

 

Promised links:

Create Your Morning Routine

AngularJS with a NodeJS proxy and more – The stack I’m using at the moment

Notice that I said just ‘stack’ and not ‘full-stack’. Angular and Node are the main components that I use in most of the applications I write nowadays. I use Angular for the front-end part and Node for the back-end which in almost all my applications, it acts like a proxy that connects to an external API or database, handles files or runs scripts locally.

Ok, what more?

Now, depending on the nature of the application, I add other technologies to the stack. For example for a PC application I might plug in Electron in the Node app. If I want to save information locally, I use Sequelize in conjunction with a database driver (e.g. sqlite3). If I put it directly on a server, then I may use MongoDB.

Moreover, you can do some pretty neat stuff with these technologies. For one of the applications I work on as my daily budget lifter I use quite a complicated stack. To give an idea on how far you can go, I will list the technologies here:

  • openFrameworks – C++ framework aimed mainly for media applications; I use it mostly for the openCV and video player capabilities
  • Awesomium – used to draw a web view in the C++ application and bind javascript functions to C++ functions
    • ofxAwesomiumPlus – an addon I contributed to, used to integrate Awesomium with openFrameworks
  • A web app using AngularJS and NodeJS connecting to a Drupal CMS API and managing a local sqlite3 database

As you can see, you can get really creative here. In the application I described above I needed complex REST capabilities, database management and a nice UI; Angular and Node were perfect for the task.

How exactly it works

A couple of years ago, I got tired of using jQuery for one of the projects I was working on and I was looking for alternatives. Angular’s popularity was booming at that time and I thought of giving it a try.

To begin with, I searched for tutorials online. Since it was quite different from jQuery, it felt a bit weird using it. Eventually I came across this great tutorial on YouTube explaining how to set up a MEAN stack application. It’s pretty much the same architecture I use today, but I improved it in many ways along the way.

To begin with, the Node part acts like a proxy for the Angular app meaning that all the REST calls go straight to Node and they are handled there. To put it in other words, Node is an API that Angular connects to.

Let’s write some code

Creating a server with Node:

Then a sample route in the API:

Having this route in the API will allow the Angular app to connect to it if set up correctly. On the Angular side I’m using a library called restangular. This library can set up a global connection to an API endpoint and then create factories to point to specific endpoints on that API. For example:

Now we can use the factory in the controllers:

These are pretty much the basics of the stack, but as I said above, you can get really creative and use these technologies in conjunction with others.

Conclusion

This was a very brief walkthrough for the Node and Angular stack that I’m using at the moment. It didn’t go into specifics too much and offered an overview on how can these technologies can be used.

What stacks are you guys using? Did you give Angular and Node a try? Let me know in the comments.

SurgTrac – Laparoscopic Simulator

SurgTrac is a Windows/OS X application I developed for eoSurgical, a dedicated team that wants to make laparoscopic training easier by allowing trainees to use a simulation environment called eoSim.

Nebulae

Nebulae is a multiplayer space shooter game that I developed for educational purposes. I always wanted to learn how to develop using the Unity3D engine, and creating an actual game from scratch was the best way to do it.

EncircledMe

EncircledMe is a project I started in the summer of 2015 with the purpose of teaching myself how to use the MEAN stack.

mean-gen

mean-gen is a generator that will simplify the process of creating a MEAN stack application. Unlike other generators out there, this one generates modularised projects with everything included for developers so they can start coding as soon as the generator completes the job.

I’ve been working on this game for the past couple of weeks and I released a version for people to test. The game is far from complete, the HUD needs more work, ship improvements will be great and lots of other features are missing. It was the first time I was using Unity3D and the first time I was doing an online game so it was quite the experience. Not sure if I will still work on Nebulae, but let me know if you think about any other cool improvements… who knows, maybe I will release other updates.

So grab a friend and jump into the Nebulae! You can find it here

I began working on another game and I will talk about it soon!

Having fun with Unity game engine

I have been missing for a while, but now I’m back with new material to write about. I finished the 2nd year of uni almost a month ago so now all I can do is wait for my internship which starts in about 3 weeks. I was really into starting to develop my web app idea(WikiMyth)  but then I stumbled upon Unity.

Unity is a really cool game engine which I wanted to learn a while ago, but had no time to do that. Less than two weeks ago I decided to go back to it and I started doing a  project tutorial that I found on unity’s learning space (the  tutorials area is really good). From the moment I began the tutorial I was hooked into it … it was so amazing, waaaay better than playing an actual game. The Unity’s editor is just perfect; you can see what you are modifying real-time, you can place objects in the world using a neat interface, you can write scripts to determine your objects’ behavior and modify your public variables directly from the editor, you can reference other objects just by dragging and dropping the object in the right space.

Script's public variables

Script’s public variables

(more…)