<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Node on New Schematic</title><link>https://newschematic.org/tags/node/</link><description>Recent content in Node on New Schematic</description><generator>Hugo</generator><language>en-us</language><copyright>Christopher Boette, CC by-sa-nc</copyright><lastBuildDate>Sun, 09 Feb 2014 06:37:43 +0000</lastBuildDate><atom:link href="https://newschematic.org/tags/node/index.xml" rel="self" type="application/rss+xml"/><item><title>Node.js errors need some work.</title><link>https://newschematic.org/blog/node-js-errors-need-some-work/</link><pubDate>Sun, 09 Feb 2014 06:37:43 +0000</pubDate><guid>https://newschematic.org/blog/node-js-errors-need-some-work/</guid><description>&lt;p&gt;Writing this in routes/api.js&amp;hellip;&lt;/p&gt;
&lt;pre&gt; exports.posts = function(req, res) {
 var posts = [];
&lt;p&gt;data.posts.forEach(function(posts, i) {
posts.push({
id: i,
title: post.title,
text: post.text.substr(0, 50) + &amp;lsquo;&amp;hellip;&amp;rsquo;
});
});
res.json({
posts: posts
});
};&lt;/p&gt;
&lt;p&gt;exports.posts = function(req, res) {
var id = req.params.id;
if (id &amp;gt;= 0 &amp;amp;&amp;amp; id &amp;lt; data.posts.length) {
res.json({
post: data.posts[id]
});
} else {
res.json(false);
}
};&lt;/p&gt;
&lt;p&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;[d'oh! Note the two `exports.posts`.]&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;hellip;and then attempting to run the Node server will through a less than helpful error:&lt;/p&gt;</description></item></channel></rss>