DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • Delivering Your Code to the Cloud With JFrog Artifactory and GitHub Actions
  • Aggregating REST APIs Calls Using Apache Camel
  • Using OKTA as Client Provider in Mulesoft

Trending

  • Supercharge Your Communication With Twilio and Ballerina
  • The State of Data Streaming for Digital Natives (Born in the Cloud)
  • Monetizing APIs: Accelerate Growth and Relieve Strain on Your Engineers
  • Understanding Europe's Cyber Resilience Act and What It Means for You
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. More on my JavaScriptCookbook Node project

More on my JavaScriptCookbook Node project

Raymond Camden user avatar by
Raymond Camden
·
Jun. 17, 13 · Interview
Like (0)
Save
Tweet
Share
2.65K Views

Join the DZone community and get the full member experience.

Join For Free

Over the past couple of days I've made more progress on the Node project I started. If you haven't read the first article, click that previous link for the background. Here's what I've been able to do since my first post.

GitHub

I mentioned this in the comments, but if you want to look at, and criticize, my Node code, you can do so at GitHub: https://github.com/cfjedimaster/javascriptcookbook. Every thing is in there except for the JSON file that I used to store authentication information for the admin panel and my GMail integration (more on that in a minute). As I think I say every time, I'm still a Node/Express noob, so I wouldn't consider this to be good code, but the site is complete for now.

Email

I used the excellent Nodemailer module to setup email support for my application. All I needed was the ability to send an email to myself and this worked fine. Here's a code snippet from my app.js showing this in action.
  var title = req.param('title');
	var body = req.param('body');
	var code = req.param('code');
	var sourceauthor = req.param('sourceauthor');
	var sourceurl = req.param('sourceurl');
	var yourname = req.param('yourname');
	var youremail = req.param('youremail')
	var tags = req.param('tags');

  var transport = nodemailer.createTransport("SMTP", {
		service: 'Gmail', // use well known service
			auth: {
				user: app.get('mailusername'),
				pass: app.get('mailpassword')
			}
	});

  var message = {
	
		// sender info
		from: '"' + yourname +'" <' + youremail +'>',
	
		// Comma separated list of recipients
		to: '"Raymond Camden" <raymondcamden@gmail.com>',
	
		// Subject of the message
		subject: 'JavaScript Cookbook Submission', //
	
		text: "Title: "+title + "\n" +
		"Body: "+body + "\n\n" + 
		"Code: "+code + "\n\n" + 
		"Source Author: " + sourceauthor + "\n" +
		"Source URL: " + sourceurl + "\n" + 
		"Submitter Name: " + yourname + "\n" + 
		"Submitter Email: " + youremail + "\n"
	
	};	

	transport.sendMail(message, function(error){
		if(error){
			console.log('Error occured');
			console.log(error.message);
			return;
		}
		console.log('Message sent successfully!');

		// if you don't want to use this transport object anymore, uncomment following line
		transport.close(); // close the connection pool
		
		res.redirect('/submitted');
	});

The only oddity I ran into was that even though I set the From to be your name and email address, when it shows up in Gmail it is always my email address. I'm assuming that is a GMail security thing. If anyone knows better, let me know. Since I include the sender's email address anyway this isn't a deal breaker for me.

MongoDB

I tell ya what. I never want to write SQL again. This isn't the first time I used Mongo but my god - what a pleasure. Here are a few examples.
//get latest
article_collection.find().sort({created_at:-1}).limit(max).toArray(function(error, results) {
			if( error ) callback(error)
			else callback(null, results)
});

//based on an array property called tags, give me unique ones
article_collection.distinct("tags", function(error, result) {
		if(error) callback(error);
		else callback(null, result);
});

//loose search
var reg = new RegExp(term,"i");
article_collection.find({$or:[{title: reg},{body:reg}]}).toArray(function(error, results) {				
		if( error ) callback(error)
		else callback(null, results)
});

I think that $or search is the one I like the most.

Templating

I hate the Jade templating system and EJS is ok, but my favorite templating system is Handlebars. The HBS module gives me access to that inside my views. I can even extend it with my own utility functions. Here is one sample view:
<h3>{{article.title}}</h3>

<p>
{{article.body}}
</p>

{{#if article.sourceauthor}}
Original Author: {{article.sourceauthor}}<br/>
{{/if}}

{{#if article.sourceurl}}
Original Location: <a href="{{article.sourceurl}}">{{article.sourceurl}}</a><br/>
{{/if}}

<p/>

<pre>{{article.code}}</pre>


<p>
{{#if article.tags}}
<b>Tags:</b>
  {{#each article.tags}}
	<a href="/tag/{{urlFormat .}}"><span class="label label-info">{{.}}</span></a>
	{{/each}}
{{/if}}
</p>

Commenting

Yeah, Disqus. Done.

Hosting

I love AppFog. How much do I love AppFog? AppFog is this:

Let me describe what their process was like for me.

  • I signed up.
  • I made a new app.
  • I clicked about 2 buttons to add Mongo support.
  • I installed the command line tool via npm.
  • I typed "af update javascriptcookbook"

That's it. I was done. Period. And it worked! Now it turns out I was supposed to modify one line: app.listen(3000) needed to change to app.listen(process.env.VCAP_APP_PORT || 3000). But even before I did that it worked. Heck, I didn't even have to tweak Mongo.

So now my process is - I make some changes - I commit to GitHub - I push up to AppFog. The update process for AppFog takes about 20 seconds.

I'm so happy with them that I'm going to ahead and take the plunge and spend the 20 bucks a month. (Although I'll probably end up putting an Adsense ad on the site to help pay for it.)

Want to give it a whirl? Check it out here: http://javascriptcookbook.aws.af.cm. I am definitely looking for some submissions now and would love someone to make a favicon if they feel so inclined. ;)

code style GitHub Gmail app application Snippet (programming) Commit (data management) JSON

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • Delivering Your Code to the Cloud With JFrog Artifactory and GitHub Actions
  • Aggregating REST APIs Calls Using Apache Camel
  • Using OKTA as Client Provider in Mulesoft

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: