This repo provides an npm package for interacting with NuID APIs within Node.js applications.
Read the latest package docs or checkout the platform docs for API docs, guides, video tutorials, and more.
This package is written with typescript so you should be able to get valid type definitions in your editor when importing this package. Using typescript is not a requirement to use this package.
With npm:
npm install @nuid/sdk-nodejsOr with yarn:
yarn add @nuid/sdk-nodejsExample server endpoint handled by express.
For a more detailed example visit the Integrating with NuID guide and its accompanying examples repository with a Node.js + express.js example .
const express = require('express')
const nuidApi = require('@nuid/sdk-nodejs').default({
auth: { apiKey: process.env.NUID_API_KEY }
})
const app = express()
// See links above for more complete examples
app.post('/register', (req, res) => {
return Promise.resolve(req.body.verifiedCredential)
.then(nuidApi.auth.credentialCreate)
.then(res => res.parsedBody['nu/id'])
.then(nuid => User.create({ nuid, email, first_name, last_name }))
.then(user => res.json({ user }).send(201))
.catch(err => res.json({ errors: ["Failed to create credential"] }).send(500))
})
app.listen(process.env.PORT)