Socket
Socket
Sign inDemoInstall

cmajor

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmajor

CMajor is a RESTful API framework for single page applications using NodeJS and MongoDB


Version published
Maintainers
1
Created
Source

CMajor

NPM Version Dependency Status Downloads Per Month

CMajor is a RESTful API framework for single page applications using NodeJS and MongoDB

Support

Installation

First install node.js and mongodb. Then:

$ npm install cmajor

Getting Started

Getting started with CMajor is super easy! Here is how you make a simple http server which has a RESTful API GET endpoint...

var app = require("cmajor");

app.get("/my/first/endpoint", function (request, response) {
   app.respond.text(response, "Hello RESTful World!", 200);
});

app.start(false, 8080);

It's as simple as that! CMajor takes care of serving files automatically so you don't have to worry about implementing that yourself! When using CMajor we put all of our client side code in a folder called "app". CMajor automatically goes to this folder when looking for a file the client has requested. This separates the server file system from the files which should be available to the client. Not only is this a way to make front-end code portable, it also protects you from anyone sniffing around your directory tree!

Let's take a closer - line by line - look at what is going on here!

var app = require("cmajor");

The first thing we need to do is create a variable, in this case "app", and load the CMajor framework into it. This gives us convenient access to CMajor's functions.

app.get("/my/first/endpoint", function (request, response) {

Here we are creating a "GET" request listener which listens for any HTTP GET requests on the "/my/first/endpoint" route. It is important that we pass in the "request" and "response" objects in our callback. This gives us access to all the raw data we need to talk with the client. Don't worry too much about what goes on in the background with these objects, CMajor does all of the hard work for you!

app.respond.text(response, "Hello RESTful World!", 200);

What we are doing here is telling CMajor to send a simple text response back to the client. We need to pass it the "response" object so it has access to the data needed to talk to the client. The second argument is the text we want to send to the client's browser. The third, and last, argument is the HTTP status code; 200 meaning "Everything went OK!".

app.start(false, 8080);

Lastly, we need to start the HTTP server using CMajors "start" function. The first argument tells CMajor if you want to run a secure HTTPS server or a regular HTTP server. In this case we are going to start a regular HTTP server. If the first argument were "true" you would need to add a third argument giving CMajor access to your SSL and CA certificates.

That's it! It's that simple to get started with the CMajor framework! If you would like to learn everything you can do with CMajor, check out our Wiki Page for more information.

License

MIT

Keywords

FAQs

Package last updated on 20 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc