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.

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…)

A few days ago I moved my website to a new server so it’s not hosted on the little PI anymore. If anyone visited my website these days and encountered errors or other things that shouldn’t be happening was because I was having some plugins problems and not enough time to fix them.

As saddening as it sounds, the raspberryPi will retire later this day. This doesn’t mean I won’t have other tasks for it though. There are lots of things you can do with these small computers.

The look of the blog has obviously changed too. I still have to do a little polishing here and there, but I quite like the new theme. It’s way lighter than the other one. Let me know what you think!

Under the Radar

So I have been kind of “under the radar” for the last three weeks or so. This was mainly because the uni trimester is about to end and all the projects I had were due. I was stuck coding all day that I almost felt sorry for my keyboard(s) as I was typing like a mad man and occasionally imagining myself throwing the keyboard along with the laptop out the window.

I maybe sound like I crybaby there, so don’t take me wrong, those were only some of the emotions I had briefly during the projects, nothing more. I actually quite enjoyed these past few weeks; I like keeping myself busy and if I can keep myself busy writing code and learning new stuff…well that’s a huge win situation.

(more…)

Building a simple game for Android using libGDX #3

In this part we will pay more attention on how the game looks and feels. If you haven’t already, I suggest you to go and check out the other parts (Part 1 & Part 2).

We will build two more screens for the game, one will be the starting screen(menu) from where we can start the game and the other one will be the ending screen which will be triggered when the player loses all of his lives (this screen will have a button that will redirect the player to the starting screen).

This is how the screens will look like:

(more…)

Building a simple game for Android using libGDX #2

A few days ago I made an introduction to the framework we are using to develop the game (libGDX), we set up a workspace, spoke about the game we are going to develop and managed to go through a bit of code that renders the background. If you haven’t already done so, I suggest going through part I before continuing with this one.

In this part of the tutorial we will implement most of the game’s features! I can feel the excitement already!

(more…)

Building a simple game for Android using libGDX #1

I participated in an app jam (AppJam2014) recently and I managed to win it with a simple android game. We had 6-7 hours to do it so I had to be modest and start a small project.

Here is a gameplay video:

I saw this as the perfect opportunity to do my first programming tutorial as I will explain some easy steps in setting up an android project with libGDX and then building the actual game using the framework. You won’t need much experience in programming to do this, but you should have a bit of knowledge in using Java and have an understanding of object-orientation.

(more…)