Follow this guide to make your NodeJS translated website SEO-friendly, and work with optimal performance.
This guide is aimed for Express.js servers. If you are using a different framework in NodeJS, contact [email protected]
1. Install the Bablic npm package
npm install --save bablic
2. Add Bablic middleware to your app.js file:
Javascript:
const {create} = require("bablic");
app.use(create({
siteId: '[your site id]',
rootUrl: 'http://[root url of your site]',
subDir: true, // if you want to use sub dir for languages like /es/ /fr/
}));
app.get('/',function(req,res) {
console.log('the current language for the user is',req.bablic.locale);
res.render('index.ejs',{});
});
Typescript:
import {create} from "bablic";
app.use(create({
siteId: '[your site id]',
rootUrl: 'http://[root url of your site]',
subDir: true, // if you want to use sub dir for languages like /es/ /fr/
}));
3. Add the snippet to your layout html template to make sure your snippet is always updated and performs optimally: (This example uses EJS templates, but the bablic local can be used in any rendering language)
<html>
<head>
<%- bablic.snippetTop %>
</head>
<body>
<%- body %>
</body>
</html>
Sub-Directories
To enable sub-directories simply use set "subdir" as true, to the Bablic middle-ware.
That's it. You can go on and click "Verify" on your Bablic SEO Configuration Wizard and complete the integration.