 Okay, so you need a Node.js add-on, well, it's kind of fast because you might need more performance in Node.js or you have a native library that you want to, you want it to be used in different languages, for example Ruby, Python, and then you write bindings for that library of yours, or you want more freedom in memory management, or you might even want to use some low-level APIs in your application in Node.js, you just can't without the proper binding, or you don't even like JavaScript, but that's not a good reason. Alright, so I have to write a Node.js add-on, I searched it and C++ shows up, not a fan, and I hope you are not a fan of C++ because this is the Rust room, so I found Neon, Neon is a project to bring Rust and Node.js closer, well, it helps you to write bindings, so it's quite easy to get started with. This is not very visible, but you could install a CLI from NPM and you can easily create a new project with Neon, new, and then it will tell you that, hey, this is your JavaScript file and this is your Rust file, now they are connected. So this is an example of a Rust file that exports a module to Node.js, so this is the example that Neon actually gives you, it's quite simple, what it does is just returns the hello-node string and then on the other side, you can see on the JavaScript side on the right, you require the module and you call the hello method and when you run it, it works. So there is, you can see there is a Neon created a register module macro and then using that you can export your functions and at the same time it also, it brought the JS types that, for example, here we use the JS string, so there is like JS null, JS undefined, JS number, it's all these things and it built this on top of the V8 bindings, which is, V8 is a JavaScript engine for Node.js. All right, so talking about performance, so some people say that, okay, we want to use this, we want to write in Rust, because I think Rust is going to be way faster than Node.js, it's going to be way faster than JavaScript, but do not under-estimate JavaScript, it can optimize it, well it can be never like Rust, but it can get pretty close sometimes, but it's also hard to optimize it, so if you're good at JavaScript, it may be better to just optimize it and see if it matches your goals or not. So whenever you make a call from the JavaScript LAN to the Rust LAN, then the V8 has to do a certain number of checks and these things cannot be optimized, so try to avoid it as much as possible, so like the best, if you're using the library for performance and let's say you have a lot of data to be processed, you want to send all the data at one shot to the Rust code, process it and then send it back, so do not call the Rust code from JavaScript multiple times during this, because that would be expensive in terms of performance. So same thing goes with interacting JavaScript objects from Rust, so in this example you can see that we create a new JavaScript object and then we try to set three properties and this potentially might call the JavaScript code from the Rust because in JavaScript you can set setters on objects and this will also be expensive, in fact I would say for setting properties in objects as much as you can, try to do it in JavaScript code because V8 will optimize your code but this is not optimized code anymore. And if you have a lot of data trying to use buffers which is a Node.js data type that refers to a space in memory and they are much faster than strings when you send them to Rust. So you saw this call.scope and you're probably wondering what is that, why you have to pass it around, so JavaScript is a garbage collected language and V8 wants to know that where this object belongs to and which function belongs to, so if that function goes out of scope it can garbage collect those values that were created there. So this call.scope is the way that you hint V8 that hey this for example this string that we are creating it belongs to the function that called it. So you have to pass around call.scope whenever you create a new values. Buffers, this is something about them. So like I said it would be faster to use buffers around rather than strings. Here's a small example of buffers that in this example you get, does this work? Great. So you have, you can access the arguments of your function that for example is exported to JavaScript. This require makes shows that it has that argument, the first argument and then it will convert it to a JS buffer. So it will cast it to JS buffer. So then once you have your buffer you want to get the data out, well you have to call this .grab method which creates a lock because you don't want to be messing around with the data in memory whenever you're in Rust because assuming that you could be on another thread and then there is a JavaScript thread rezoning you want to acquire a lock and make sure that nobody else is touching that data and it is in a cost instant state. So this grab takes care of that and then in here you can get the data or mutate the data. So in this case you are converting to a slice and then so just for this example for that I should also show that I have to create a new buffer. So it's quite easy just pass the scope and then the length. So in this case I wanted to just copy this buffer that the function was called. So in this case we just get size of it and then I have to call the grab method again so it can create a lock and then in this case we will so you put the mute so then we say that this argument is going to be muted and we just say that copy from slice which copies that original buffer into it. So then we can return that buffer and then JavaScript has a new buffer around. All right so classes. So Neon created another macro for creating types. So you can have your own Rust classes in Neon and then you can use them in JavaScript, have the same some methods and some properties on top of them. Maybe you can also have some hidden properties there. So Neon makes it easy. It gives you a you have to make a any method. So with this in that method you will create your object and then make sure that all the arguments for it are there. So this is in JavaScript we would call that the constructor and then here's another method hello. So which have two arguments, sorry one argument and then which is a name and then also accesses this argument in the method which in JavaScript refers to the object itself. So which refers to this whole gritter object and in this case we also have to use this grab method to make sure that we can get our gritter object and get this original string that was put there from it. So in case and you have to call the grab so it creates a lock around it make sure it's not modified in the JavaScript land. There is also tasks for background jobs. So for example you have some synchronous code that you want to run. You can use tasks and then it will use the V8 API to create a thread in the background and it can do some heavy computation without blocking the Node.js main thread. So in this case you can for example calculate all the Fibonacci numbers. I should have an argument I forgot that. So you would have a perform function that that you do whatever needs to be done in that thread and then you will also get a call when it's completed and then you can convert the results to the JavaScript values in there or through an error. And running it is quite easy. You just call the schedule task sorry schedule method of your of your object. So there is another tip. There is something called the project called not neon 3rd day. I'm not sure if I'm pronouncing it right but it makes it quite easy to write code with neon because it takes care of all the conversion of the arguments and everything. So this is also a module that is exported to the Rust land. So you can see that it's quite simple Rust code and it doesn't have any of those it doesn't have any conversion of the arguments to the Rust types and back and forth. So it's quite good. It's quite good. I say try because I'm not sure about the performance requirements for your project. This might be a little bit slower than I think it is. And at the same time it's a new project so things might go wrong and sometimes some people are not fan of abstractions too much. So it might be a little bit too much of an abstraction for you but if you want to just try things out it's quite good. So who uses neon? Well I think it's not it's not very visible that but in the MPM registry I could I did a search and there was more than a few projects interestingly use neon. I was surprised actually. One of the most interesting ones is Leap Sodium which is is Node.js binding to Rust Sodium and it is used in the wire app which is a messaging app. So that's and then they are one of the contributors to this project which makes it even more interesting. So aside that I saw that there are a few more cryptography modules in them that are written with Rust and then exported to Node.js which makes sense because you probably want to want to do some sensitive stuff in your Rust code that is that has a high performance and then you return your buffers to Node.js to be used there. It makes a lot of sense to use Rust to write cryptographic code in JavaScript in short. So at that there's some there is some compilers and parsers that are written for Rust and this is a good thing because so you would write your own for example library. Let's say it's a compiler and then you would write bindings for it in different languages for example one for JavaScript, one for Ruby, one for Python, one for Java and then you only have to write your library once but it can be used everywhere. It also makes sense if you don't like all those languages and you want to use your own favorite Rust. So there's a lot of examples like that with C++ for example LeapSas which is a transpiler for converting SAS code to CSS which makes it easier for some front-end developers to write in a better language than CSS and LeapSas is actually in written in C++ but it has bindings for all the different languages. So a good example of this kind of is this type of library. The reason I'm saying that is that I'm hoping that you guys are Rust developers and you would go on and create some Node.js modules for somebody like me to use. Anyway, so talking about being a little bit shorter than I thought. So there's about the examples. Neon is quite new so you will go to the website and you will see there is nothing there. So I found a few and then looking around and trying to experiment. So here they are. It would be nice if you if you ever write any if you try something and then you could add on your examples to the Neon example project. It would be appreciated. So yeah. Any questions? Well, what's the best practice for Rust developers to write the JavaScript APIs documentation? Is it? All right, tricky question. Well, there is a lot of JavaScript projects and all of them use different tools to have their own documentation and to build up their website. So I think one of my favorites is the JS doc module in which compiles your code, which compiles your documentation and makes an HTML page from out of it. It might be in the past because it's been a while that I have maintained any project. But I think the thing is that if you have a look at some new JavaScript projects with all the bells and whistles, and they can have a look around on what tools they use, I think that would be the best. That's another problem in the JavaScript world that everything changes every year. And me as a JavaScript developer, I cannot keep up with it. So I hope I answered your question. No, no. It's my understanding that I might be wrong. It's a guess from the project description that lip sodium is written in Rust. And then the wire messaging app is written in Node.js. And then they use the bindings that they wrote for lip sodium. How is it to distribute Node.js module with neon and Rust bindings in NPM? So neon takes care of it. Luckily, it gives you one command, neon build, and it will build your code, and it's ready to be imported from JavaScript. At the same time, you put your Rust code and your JavaScript code in your project. And then in the package.json, you put neon build as an installed script. So whenever the package is installed, it will build the module. And then you can publish that as an NPM project on NPM. All right? The other thing, something I forgot to mention that you would also have to install the neon CLI as a dependency to your app. And then, which would be automatically installed whenever your user installs it. But Rust wouldn't be installed with it. So you have to tell the user that install Rust as well. Well, you could also build your binaries ahead of time, and then download them whenever the project is installed. But I'm not sure how that would work out because I don't have any experience in building binaries for multiple platforms. That would be a bad idea. So he asked, would it be feasible to install Rust beside your package whenever it's installed? And well, you don't want to mess with the user that they have their own Rust installed. But one thing that you could do is that you would install the, for example, well, don't install it. Have a local binary of loss downloaded to your package folder, and then try to use that. Hopefully, you can configure neon to be smart about it and use that binary instead. Not sure if neon can, you can do that with neon. Maybe if you mess it around with the path variable. So yeah, it's a kind of, I guess that's kind of uncharted territory. All right. Any more questions? Thank you very much. So Dave Herman is the original maintainer. So thanks to him. I'm here. Yeah, that's it.