I’m starting a new project with a group of kids to program a plagiarism app for my school. After debating between PHP and Node.js, we decided to use Node.js as our primary ecosystem. After a bit of research and a couple of YouTube videos, I set up my own simple web server. My repository can be found here.
Here are the basics:
- Node.js can easily create a local server to compile, build, and emulate your web-based code
I worked briefly with Node.js over the summer at Salesforce.com when I was a UX Engineer, but I had never truly dove into the compiler I was using. I was under a lot of time pressure and was behind the learning curve, so I simply accepted what came out of it.
It’s all coming back to me now and I’m realizing that I actually do understand a great deal of what’s going on. Here are some basics that I used over the summer that people should know:
Node.js and NPM Node.js also built NPM - Node Package Manager - which is the default package manager for Node.js. It is responsible for downloading, importing, and including open-source packages, or libraries if you will. These packages are largely user-contributed and can be downloaded and included like so:
Packages are a super easy way to install predefined functions that can do common things. They’re incredibly simple and easy to pick up.
You never want to include packages themselves in repositories. They take up space and are simply non-essentials. Because of the nature of open-sourced code, packages are mostly all available online to be installed by anyone. To share dependencies, you need to create a ‘package.json’ file — a file that specifies which packages should be included.
To create the ‘package.json’ file type, type (in Terminal):
To log a dependency in the ‘package.json’:
If you wish to install all the packages specified in the ‘package.json’ file, simply type:
This will install all the required modules. This sytem makes sharing code incredibly elegant and easy!
Must export your data in module2 otherwise it just reads an empty object:
Creating a Simple Local Web Server
It’s very easy to start your own web server to run compiled code. It’s great for prototypes and running web apps locally. Here’s a simple web server that highlights the basic functionality:
Hope this helps! I’ll be updating my site with various Node.js content and updates on the Plargiism App. In the meantime, if you have any questions feel free to reach out