The synaptic page, with the demo up and running
Running Node Apps
So, I bumbled about for a while trying to work out what I’d need to get this to run. The documentation for synaptic actually does a really good job of telling you once you have the context to understand the things its saying. And it didn’t take me that long to find it out.
So once Node and npm were installed, I did some reading up and rememberes about client and server side code. Node JS is a server side technology. That means that scripts you write are naturally meant to exist on the machine where the web page lives. For Node, that means you can pretty easily run the script on your machine using the terminal. On the command line I just typed
This should work. But I got nothing. It took me some puzzling before I realized I had Node but I didn’t have the Synaptic library code! The following npm command installs it for you; “npm install synaptic –save” and you’re good to go. You need to provide the node command “require()” to inform the runtime that it needs to grab the Synaptic module. Rerunning the node command worked like a charm!
Running in the Browser
So to get it running in the browser (I use chrome), I had to create a simple html page:
Which includes the Synaptic library code ahead of my script. The script I wrote did need a slight modification though. The “require” line is actually a Node function, which means the browser can’t interpret it. But, we’ve already included the Synaptic library from our script html tag, so we actually don’t even need it. A quick delete and a refresh and I had the code running. You can see this by right clicking and selecting Inspect. The panel that pops open has a tab at the top for console, and with that open you should see the output from the script if all went well.
So there you have it. My experiences with running Node for the first time, using the Synaptic library. I learnt a lot from doing it. And for any beginners out there, I hope this helps!