Using the new Express 4.0 Router to build an API
- Node and npm
- Clone the repo:
git clone [email protected]:scotch-io/node-api
- Install dependencies:
npm install
- Start the server:
node server.js
Test your API using Postman
Building a RESTful API Using Node and Express 4
Using the new Express 4.0 Router to build an API
git clone [email protected]:scotch-io/node-api
npm install
node server.js
Test your API using Postman
When I have lots of routes to config, how to manage these routes in a anther file(files)?
And What I should include the routes file in the server.js?
I'm a rookie.
Thank you.
webonise@webonise-desktop:~/JavaScriptProjects/node-api$ node server.js
Magic happens on port 8080
/home/webonise/JavaScriptProjects/node-api/node_modules/mongodb/lib/utils.js:99
process.nextTick(function() { throw err; });
^
MongoError: auth fails
at Function.MongoError.create (/home/webonise/JavaScriptProjects/node-api/node_modules/mongodb-core/lib/error.js:31:11)
at /home/webonise/JavaScriptProjects/node-api/node_modules/mongodb-core/lib/connection/pool.js:483:72
at authenticateStragglers (/home/webonise/JavaScriptProjects/node-api/node_modules/mongodb-core/lib/connection/pool.js:429:16)
at Connection.messageHandler (/home/webonise/JavaScriptProjects/node-api/node_modules/mongodb-core/lib/connection/pool.js:463:5)
at Socket. (/home/webonise/JavaScriptProjects/node-api/node_modules/mongodb-core/lib/connection/connection.js:309:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
webonise@webonise-desktop:~/JavaScriptProjects/node-api$
It seems as I can't connect to the DB. If I try to make a POST on api/bears with the key[name=Klaus] using POSTMAN nothing would happen (I followed you instruction on http://scotch.io/tutorials/javascript/build-a-restful-api-using-node-and-express-4 ).
Hello, Thanks for the tutorial, such a bug a fan of scotch(io). When I'm running the tutorial (and even running the cloned repo here [with no changes] the name of the Bear will not save, and whenever I get all the bears they just have _id and __v properties, is there an update that changed the way we should write the creating post? thanks!
Cannot GET /
can't run node server.js
as it gives me the following error.
node-api/node_modules/mongoose/node_modules/mongodb/lib/utils.js:99
process.nextTick(function() { throw err; });
^
MongoError: auth fails
at Function.MongoError.create (/Users/iflix/code/mine/node-api/node_modules/mongoose/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/iflix/code/mine/node-api/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:483:72
at authenticateStragglers (/Users/iflix/code/mine/node-api/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:429:16)
at Connection.messageHandler (/Users/iflix/code/mine/node-api/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:463:5)
at Socket.<anonymous> (/Users/iflix/code/mine/node-api/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:309:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:543:20)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.