Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng

Full-stack AngularJS with no dependencies

  • 0.0.1-experimental5
  • npm
  • Socket score

Version published
Weekly downloads
5K
increased by5.61%
Maintainers
1
Weekly downloads
 
Created
Source

ng: full-stack angular (warning! pre-alpha)

With node.js came full-stack javascript. However, developers still had to use different frameworks to build frontend apps and their backend apis. Enter ng, now there is an elegant, full-stack AngularJS framework with no other dependencies

While still in pre-alpha, ng is being built for production environments with sponsorship by Pook-n-Cheek. If you are interested in contributing to the project, email adam at adam.kircher@gmail.com

example

//Enter in the url or file path of module dependencies. ng will load them first
var modules =
{
	ng:'//ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js', 
	ngRoute:'node_modules/ng.cdn/1.2.0-route.js' 
}

require('ng')(modules, function(ng)
{
	//ng is a listener that accepts a request & reponse
	require('http').createServer(ng).listen(1337)

	//Just like most node.js frameworks ng uses a stack of middleware
	//however its middleware uses Angular's interceptor API. Valid
	//properties include request, requestError, response, responseError
	//The example below sends an app's base template if the response has no data
	ng.stack(function()
	{
		return {

			response:function(data)
			{
				//ng.toString() will concatenate all modules, replacing
				//the need to specify each one manually.  To do it the
				//manual way replace ng with the three lines below:
				//'<script>'+ng.module('ng')+'</script>',
				//'<script>'+ng.module('ngRoute')+'</script>',
				//'<script>'+ng.module('example')+'</script>',
				return data ||
				[
					"<html ng-app='example'>",
						"<head>",
							ng,
						"</head>",
						"<body>",
							"<div class='ng-view'></div>",
						"</body>",
					"</html>"
				]
				.join('\n')
			}
		}
	})

	//Now we are done with ng specifics, the rest of our app looks
	//almost exactly like angular!!!  Look carefully to spot some
	//nodejs specific functions like require/readFile/__dirname etc.
	.module('example', ['ngRoute'])

	//Because it has a require, this factory will be placed the server.
	//If you access from the client - e.g., in a controller - then ng
	//will send an http request run the function on the server and
	//return the result, so it will look like it was run on the client
	.factory('$os', function($http, $cpus)
	{
		var os = require('os')

		return [os.cpus, os.cpus]
	})

	//This factory will be put on server and client
	//it will be run from whereever it is accessed
	.factory('me', function(us) { return 'hi' })

	//Easily import 3rd party code such as a db factory/directive
	.factory('db', require('ng.cql').factory)

	.directive('db', require('ng.cql').directive)

	//Controllers are automatically put on the client
	.controller('base', function($scope, $os, $cpus, $http, db)
	{
		$scope.test = db('test').select('*')

		$scope.os = $os[1]()

		$scope.version = ng.version
	})

	//Configs/runs are put on client and server. We make an exception
	//for templates, where the template parser will run the template
	//on the server (readFileSync in this case) and push that result
	//to the client config.  All config/runs are put on client as-is
	.config(function($routeProvider, $locationProvider)
	{
		$routeProvider

		.when('/george', {
			template: require('fs').readFileSync('view/george.html'),
			controller: 'base'
		})

		.when('/adam',
		{
			template:require('fs').readFileSync('view/adam.html'),
			controller: 'base'
		})

		$locationProvider.html5Mode(true);
	})

	//OPTIONAL ADVANCED USAGE

	//Internally ng pre-processes your module code, this functionality
	//is added to the public api as ng.parse(), allowing cool things like
	//automatically creating angularjs's inline injection array,
	//or making your code pretty with automatic indentation.
	//Include these stock parsers by specifying 'inline' and/or 'whitespace'
	ng.parse('inline').parse('whitespace')

	//Make your own custom parsers using the function signature below
	//For more example's look at the stock parsers in parser.js
	//.parse.client() and .parse.server() provide more granularity
	.parse(function(fn, type, name)
	{
		//Uncomment lines below to see how a custom parser works
		//console.log('I am parsing', type, name)
		//console.log('Function to parse & return', fn.toString())
		//console.log('Module API available as this', this)
		return fn  //I didn't do anything, kept function as-is
	})
})

##todos

  • Many, many ideas. Feel free to email me suggestions!
  • Rpc requests need to have authentication hash
  • More stock middleware, gzip etc, and more stock parsers
  • Testing API
  • Make namespace use self-executing function rather than setting a global var

##related projects

  • ng.seed: create a modular ng application using npm packages
  • ng.cql: realtime cassandra database syncing

Keywords

FAQs

Package last updated on 08 Feb 2014

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