What to exepect coming from Nodejs 7+

Posted on
  • I am set to buy a couple espurinos. I've been coding for RPi so I can use the latest node 7 (in linux).

    Can someone summarize the major issues I will have coding for/with espruino?

    examples: Supports CommonJS? (i.e. can use npm??), I use node-serialport, but there is no binary for espruino right?? can I use socket.io? How about any ES6? Promises?, all of ES2015 supported except what was mentioned (no regular expressions :( )?

    Just wanting to have a better idea of what I am getting into.

  • I think it's probably best if someone less biased provides their feedback, but:

    • Your biggest issue will be that you're developing for a fundamentally different device with a lot less memory. Your Pi probably has ~1,000,000,000 bytes of RAM, but the Pico has just 100,000.
    • You can't realistically use NPM. There's an option in the Web IDE that half works, but every single Node.js package I've tried to use depends on so many other packages it fills up all the memory immediately
    • You don't need node-serialport, because there's a built-in Serial1/2 object. Just use on('data',..) and write/print/println
    • It's very unlikely you'll be able to use the socket.io library as it'll be too big - but that's not to say you can't use websockets via Espruino's ws library.
    • The latest builds support Template literals, Arrow functions and Promises - but not much else from ES6. You'll want to use one of the 'cutting edge' builds though as even 1v89 had some slight issues with the Promise implementation.
    • Not all of ES5 is supported (for instance no unicode), but on the whole pretty much all the JS people use on a daily basis is there
    • If you need WiFi you'll probably want an Espruino Wifi board. You can add an ESP8266 to a Pico but it'll involve some relatively fine soldering which you may want to steer clear of at first.

    Basically, if you just write JS code and use the modules that are available for Espruino (which tend to be quite memory efficient) then everything will be great. If you expect to use a module for everything rather than just using the standard API functions then you'll probably be disappointed.

    Espruino isn't a Raspberry Pi - you need to think of it more like an Arduino for JS devs. You get really low power consumption, <0.1s boot time that always powers on in the same state and a small size - but there are some compromises (but far less than if you had to write C on an Arduino!)

  • Issue or challenge... I'd rather focus on the latter...

    you're developing for a fundamentally different device...

    That statement is key!

    Device with totally different purpose and context constraints - enablers and inhibitors.

    1.024E+5 vs 1.024E+9, single vs quad core, 84MHz vs 2.8+GHz, deep sleep vs idle, 0.12mA vs 200mA, running on source vs JIT c'd,...

    Nevertheless IS exciting to code on both sides of the fence...

  • 0.12mA

    I think it's nearer 0.02mA now on the Pico, or 0.002mA on Puck.js ;)

  • @gordon that was an excellent reply, exactly what I needed to know. This information should be in some form in their FAQ/Docs/Wiki since more than likely an Espruino adopter would be coming from coding nodejs. It's absence prompted me to use the forum. (espruino folks listening here?)

    So summarizing your post

    I should expect to just write code that calls the API mostly. There is a package manager and module system (still commonjs?) but use it sparingly if at all. Don't count on using any package from NPM unless it has very few or no dependencies. At least for now there is limited ES6.

    Actually being an ole geezer I can remember the good old days of the first IBM PCs and trying to get your (FORTRAN/BASIC) program to fit into 128K. It's back to the future..fun

  • Thanks!

    Yes, I'll try and add something...

    The packaging is commonjs-style, but quite basic. If you require something it'll look on http://www.espruino.com/modules/ (or wherever you configure), which is built from user-contributed modules on GitHub.

    You can set up a directory locally and grab modules from that, or can even just require a URL if you want to load something up directly.

    There are also command-line tools (npm install espruino) if you want to use your own IDE.

    But basically: if you spend your time trying to copy your existing Node.js projects you will probably get frustrated.

    Approach it as you said - with the attitude that you're working on a constrained device - and writing code for it will be fun. It's worth reading http://www.espruino.com/Performance

    I'd also really recommend using the REPL in the IDE heavily as well, especially when dealing with hardware - being able to 'poke around' from inside the CPU is fun, and when you get used to doing it it'll save you hours of debugging.

  • It is also worth noting that there is a Linux build, so you can test out on the raspberry pi.
    Not all of the hardware interfaces are there, but you can give it a whirl from the pi.

  • @Gordon...

    nearer 0.02mA now on the Pico, or 0.002mA on the Puck

    0.066 ... 0.0066 Watts compared to 1.0 ... 0.4 Watts? - tips the scale even more towards destiny... ;-)

    There was a time where power consumption was so beyond reasonable for unplugged use that (power) wire(s) were accepted without comment. With the tizillion IoT things we would suffocate in wires, worse than anything in a spider's web...

    Though we still have (www) communication is because the grid of connection points is much finer and multi-layered...


    ...good old days...

    exactly, same principles apply: focus on the essential, distill the solution down to a the point where required === sufficient. Everyone can throw resources at problem... but solving it is granted to others...

  • @user70533 the espruino website has a lot of info for getting started. http://www.espruino.com/Modules shows how to use modules and http://www.espruino.com/Reference has details about everything built-in. On the whole, I've been able to easily port code between node and espruino and just replace the modules and their calls with equivalents, it didn't take long to get used to. Definitely a lot easier, more powerful and faster than making a jump to writing c for arduino, and having a command line to work with on your microcontroller is amazing!

  • I think @Gordon summed it up well, but in addition to the constraints the application space differs too. As a microcontroller, the Espruino efficiently handles sensor and actuator device interfaces to collect and process real world data. NodeJS on the other hand builds Internet web services. Personally, I don't favor the notion of using an OS dependent system such as NodeJS to triddle hardware, nor the naive idea of exposing a primitive microcontroller board like Espruino directly to the Internet. Remember Maslow's hammer -- when all you have is a hammer, everything looks likes a nail. Espruino and NodeJS, while both JavaScript based give us two different tools, so choose the best tool for the job.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

What to exepect coming from Nodejs 7+

Posted by Avatar for dgk @dgk